1

I want to make a sort of Json-server in android to make some REST calls in my app. I create this WebServer:

public class WebServer extends NanoHTTPD{

Context context;

public WebServer(Context context){
    super(8080);
    this.context = context;

}

@Override
public Response serve(IHTTPSession session) {

    String msg = "[";
    int id = R.raw.frame_1;
    for(int i = 0; i<10; i++) {
        InputStreamReader inputStreamReader = new InputStreamReader(context.getResources().openRawResource(id + 1));
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
        String line;
        try {
            while ((line = bufferedReader.readLine()) != null) {
                msg += line;
            }
        } catch (IOException e) {

        }

        if(i != 9){
            msg += ",";
        }
    }

    msg += "]";

    return new NanoHTTPD.Response(msg);
}

So I create a sor of JSON Array. Now I want to make some Rest calls like GET http://localhost/?frame_id=1, how can I do that?

Quarillion
  • 65
  • 2
  • 9

2 Answers2

0

Please, can you explain your aim in a more exact way. I think you want to get rest uri, right, If it is, session.getUri() will work

Azam Rahimjonov
  • 108
  • 1
  • 9
0

If you want rest part of uri right, session.getUri() is the way to go.

For example, if you have http://whateveraddress.com/second_part/third_part/ and_so_on calling session.getUri() will give you string:

/second_part/third_part/and_so_on

With that you can respond accordingly.

MWiesner
  • 8,868
  • 11
  • 36
  • 70
Sherzodbek
  • 296
  • 3
  • 9