Fake API JSON Server (FAJS)


FAJS:   SOLD       




Hi guys, this time I want to share my experience regarding mobile application development, where all of this came from the weekly meeting at the company where I work.

Long story short, our team planned a target for 2023, because our manpower is limited, so each division is forced to not be able to collaborate simultaneously, for example to pursue a priority product, the backend division can only collaborate with the web division, and for the time being the mobile division is independently required to be able to create a prototype for next year's target.

In fact, a UX cannot be created without the touch of dynamic data, so the solution to get CURD access with our API is to get advice from the frontend team. to use  JSON Server , so that one day when the backend team is ready to support the mobile team, it will be easier to realize the required endpoints.

A way to get a full fake REST API without any coding effort (zero coding) in less than 30 seconds, SERIOUSLY!

Install

npm install -g json-server

Example

Create a db.json file with some data

{
  "posts": [
    { "id": 1, "title": "json-server", "author": "typicode" }
  ],
  "comments": [
    { "id": 1, "body": "some comment", "postId": 1 }
  ],
  "profile": { "name": "typicode" }
}

Start JSON Server

json-server --watch db.json

Now if you go to  http://localhost:3000/posts/1 , you will get

{ "id": 1, "title": "json-server", "author": "typicode" }

Also when making a request, it is good to know that:

  • If you make a POST, PUT, PATCH or DELETE request, the changes will be automatically and securely saved to db.json using  lowdb .
  • The id value cannot be changed. Any id values ​​in the body of your PUT or PATCH request will be ignored. Only the value specified in the POST request will be honored, but only if it has not been retrieved.
  • POST, PUT, or PATCH requests must include the Content-Type: application/json header to use JSON in the request body. Otherwise, it will return a 2XX status code, but no changes are made to the data.

Post a Comment

Previous Next

نموذج الاتصال