This library allows you to write web applications for Android. It works with Android application available on Google Play.
To find out more please visit myweb.io
You can build project by invoking on console:
$ ./gradlew build
@GET("/mypath")
public String get() {
return "Hello, World!";
}
@GET("/path/:name/:id")
public String dataFromUrl(int id, String name) {
return name id;
}
@GET("/query?:name=default&:id=0")
public String queryString(int id, String name) {
return name id;
}
Please note that if request comes without query string (just "/query") then in our example method queryString() receives values id=0 and name=default.
@GET("/produces")
@Produces("application/json")
public String produces() {
return "{ id = 1 }";
}
@GET("/assets/:filename")
public InputStream assets(Context ctx, String filename) throws IOException {
return ctx.getAssets().open(filename);
}
@GET("/response/*filename")
public Response response(Context ctx, String filename) throws IOException {
InputStream is = ctx.getAssets().open(filename);
return Response.ok()
.withBody(is)
.withMimeTypeFromFilename(filename);
}
@GET("/json/:name/:id")
public Response json(String name, int id) throws JSONException {
JSONObject json = new JSONObject();
json.put("name", name);
json.put("id", id);
return Response.ok().withBody(json);
}
In order to use myweb.io API you need to add few lines in build.gradle:
apply plugin: 'android-apt'
buildscript {
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.3'
}
}
dependencies {
compile 'io.myweb:mywebio-api:0.1-SNAPSHOT'
apt 'io.myweb:mywebio-compiler:0.1-SNAPSHOT'
}
That's it! Now you can enter
http://ip:8080/your.app.pkg/[your services]
in a web browser and see how it works.