0

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)

  • What does it mean to make a REST API using a JSON file? What do you mean by "perform requested operation"? – Ryan M Jun 19 '20 at 01:32
  • @RyanM "perform requested operation" means GET/DELETE/PUT/POST this operations. –  Jun 19 '20 at 08:41
  • @RyanM make a REST API using a JSON file, means I have some json data in a file. I can perform crud operation via api calls. [If you worked angular : this is the the exact tool i used, maybe there are similar tools also https://www.npmjs.com/package/json-server] –  Jun 19 '20 at 08:44

1 Answers1

0

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.

Helton Malambane
  • 1,147
  • 11
  • 12