Package: pyjserver
Python JSON ServerPython implementation of Node JSON Server (Flask as backend).AboutMake a full REST API without coding!pyjserver is a python implementation ofNode JSON Sever,
which creates a full REST api (with GET, POST, PUT and DELETE methods) based on json file.What's NextPATCH HTTP method.Filter data with GET HTTP method.Pagination data with GET HTTP method.InstallPython JSON Server library is on PyPi repository, so it can be installed withpip.>>>pipinstallpyjserverGet statedAfter install pyjserver, createdb.jsonfile with the endpoints and data.{"python-libs":[{"id":1,"name":"pyjserver","version":"1.0.0"},{"id":2,"name":"flask","version":"1.1.0"},{"id":3,"name":"flask-restful","version":"0.3.8"}]}Run the pyjserver cli command.>>>python-mpyjservermy-server./db.jsonOR>>>python3-mpyjservermy-server./db.jsonAnd the follow output will be displayed:* Serving Flask app "my-server" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://localhost:5000/ (Press CTRL+C to quit)Now to test the API, if you go tohttp://localhost:5000/python-libsyou will get the same json in db.json.[{"id":1,"name":"pyjserver","version":"1.0.0"},{"id":2,"name":"flask","version":"1.1.0"},{"id":3,"name":"flask-restful","version":"0.3.8"}]With the same URL, you can send POST requests to add, PUT requests to edit and DELETE requests to remove from json file.TIPfor each json key, it will be created an endpoint with GET, POST, PUT and DELETE HTTP methods.
You can also see all available endpoints in root url (http://localhost:5000/).{"endpoints":[{"name":"python-libs","route":"/python-libs"}],"methods":["GET","POST","PUT","DELETE"]}JSON file schemaFormat:JSON object with a list of JSON objects.Main JSON key:name of the endpointJSON list value:list with all records for the endpoint. To start with no data, just place an empty list[]JSONs inside the list:each record for the endpoint.DO NOT FORGET TO ADD SEQUENTIALIDKEY FOR EACH RECORD{"endpoint-1":[{"id":1,"name":"data 01"},{"id":2,"name":"data 02"}],"endpoint-2":[{"id":1,"name":"another data 01"}],"endpoint-3":[]}So the JSON above will create 3 endpoints/endpoint-1(with 2 record data),endpoint-2(with 1 record data) andendpoint-3(with no record data).
The home page for this json file will display:{"endpoints":[{"name":"endpoint-1","route":"/endpoint-1"},{"name":"endpoint-2","route":"/endpoint-2"},{"name":"endpoint-3","route":"/endpoint-3"}],"methods":["GET","POST","PUT","DELETE"]}HTTP methodsFor each endpoint created, is allowedGET,POST,PUTandDELETEHTTP method.GET>>>curlhttp://localhost:5000/endpoint-1/[{"id":1,"name":"data 01"},{"id":2,"name":"data 02"}]POST>>>curl-d'{"name": "data 03"}'-H'Content-type: application/json'-XPOSThttp://localhost:5000/endpoint-1/{"id":3,"name":"data 03"}>>>curlhttp://localhost:5000/endpoint-1/[{"id":1,"name":"data 01"},{"id":2,"name":"data 02"},{"id":3,"name":"data 03"}]PUT>>>curl-d'{"name": "data 02 edited"}'-H'Content-type: application/json'-XPUThttp://localhost:5000/endpoint-1/2{"id":2,"name":"data 02 edited"}>>>curlhttp://localhost:5000/endpoint-1/[{"id":1,"name":"data 01"},{"id":2,"name":"data 02 edited"},{"id":3,"name":"data 03"}]DELETE>>>curl-XDELETEhttp://localhost:5000/endpoint-1/2{}>>>curlhttp://localhost:5000/endpoint-1/[{"id":1,"name":"data 01"},{"id":3,"name":"data 03"}]REMEMBER:all the data is inside thedb.jsonfile, so any change with the HTTP method it will also change the file.
Consequently, if change the file, it will change the API.NOTE:if you edit the json file and add an endpoint with pyjserver running, it will be necessary to restat the application to it load the new endpoint.
But it is not necessary if you edit the file and add new records.LicenseMIT