Get a full fake REST API as soon as possible. Base on NodeJS + JSON Server.
Support more features:
-
Register user with username & password or email & password.
-
Login with registered users.
-
Protect resources using JWT Bearer authentication.
-
Upload files.
Preview: https://fake-rest-api-nodejs.herokuapp.com
git clone https://github.com/robinhuy/fake-rest-api-nodejs.git
or fork to your account and clone the forked repo
cd fake-rest-api-nodejs
npm install
or if you using yarn
cd fake-rest-api-nodejs
yarn install
-
Production mode:
npm start
or
yarn start
-
Development mode (auto reload server when editing using nodemon):
npm run dev
or
yarn dev
-
The server will run on
http://localhost:3000
. You can test with public endpoint:http://localhost:3000/products
(GET method).
All the data was placed in database.json
. Edit it to suit your purpose.
You can use https://mockaroo.com/ to mock data, and publish your code to https://heroku.com/ or similar hosting to get a Public API.
Note:
-
To protect resources, decleare resources and protected methods in
database.json
:"protected_resources": { "users": ["GET", "POST", "PUT", "PATCH", "DELETE"], "products": ["POST", "PUT", "PATCH", "DELETE"] }
-
To register new user, using endpoint
/register
, methodPOST
, request typeapplication/json
. Body request likeusers
resources: -
To login, using endpoint
/login
, methodPOST
, request typeapplication/json
. Body request like this:{ "username": "admin", "password": "admin" }
or
{ "email": "[email protected]", "password": "admin" }
-
To upload single file, using endpoint
/upload-file
, methodPOST
, request typeform-data
, fieldfile
. Uploaded file stored in/public/uploads/
. -
To upload multiple files, using endpoint
/upload-files
, methodPOST
, request typeform-data
, fieldfiles
. Uploaded files stored in/public/uploads/
. -
Change default port, database file, jwt secret or jwt token expires in
config.json
.
Please view detailed document in https://github.com/typicode/json-server/blob/master/README.md#table-of-contents
If you want to change logic of authentication or add more feature, please edit file server.js
or additional_routes.js
.