Customization
This section will brief about how to add custom APIs (or update existing APIs) in your existing mockbee template.
#
Design an APIDecide
- End Point (the url that you call from frontend)
- Methods (get, post etc.)
- Does it require Authentication?
- What the API returns
- What is the logic you want to put
Think in terms of Input -> Processing -> Output
View other implementations of the APIs too in the project
All the
logic
is present insidebackend/controllers
,data
is inbackend/db
and utility functions inbackend/utils
.The API endpoints are present in
server.js
You can update or add new based on this
#
Inside Backend Folder...In the
/src/backend
, there are three folders:- controllers
- db
- utils
First, you can add a Handler function in corresponding
controllers
file. If you are adding new API or feature, you can create a new file asNewFeatureController.js
.Add your logic inside that function. (Have a look at the code of other handlers to understand how you can also implement the same)
If you need some pre-seeding data for your feature, add inside
db
.Any reusable utilities can be put inside
utils
.
server.js
#
Add API Endpoint inside - If you have any new models added, add it in models object. (Have a look at other added models)
- Add seeding data from db if anything new entry is in pre-seed.
- Inside routes, the routes are added as: `this.methodName(endpoint, callback)
- The callbacks are bind with
this
because we want to usethis
reference in our handler function for db, authUtils etc.
#
Checking its working- Test the APIs with
mockman-js
. - Integrate in App after the api endpoints are working well.
#
Further Steps- We are using
mirage-js
for mock-backend. You can read these imp guides which are there on their official documentation: