Search code examples
androidjsonapidatabase-server

Build a restapi in android from JSON


Suppose I have this json file

[{"item_id":"1000","item_name":"PEn","item_quantity":"2.66","item_rate":"3.69","item_purchase_date":"2020-05-13T00:00:00Z"},
{"item_id":"1004","item_name":"box","item_quantity":"63","item_rate":"20.5","item_purchase_date":"2020-06-12T00:00:00Z"}]

I want to make a rest api using this json file in Android. This json file should be locally available in my android device. When I send a certain request (GET/DELETE/etc.) to a certain URL (localhost:3000/posts), I want to perform requested operation.

Please show me how can I achieve this.

UPDATE 1: I don't need NanoHTTPD. (Its better if I can find something like golang with postgres)


Solution

  • To serve an api on an android device, you would need a webserver. The easiest way would be to extend a Java HTTP server and add your own logic.

    Try NanoHTTPD, you can easily use it in android.