Generating an Endpoint
Tutorial Video
Below is a video showing you to use the xx new
command to create an endpoint and more
Steps
One of the advantages of using XEST framework is that you can generate your endpoints from your command line with the following command
$ xx new
Xest CLI will take you through a survey to generate your endpoint.
What would you like to generate? (Use keyboard arrow keys)
▶️ endpoint
▶️ query
▶️ migrations
▶️ seed
You can choose which one you would like to generate with the arrow keys, in this case we will be choosing GET
What type of endpoint will this be?
▶️GET
▶️POST
▶️PUT
▶️DELETE
▶️All of the above
After choosing the type of operation you need to choose the table that this endpoint will be based on.
What will be the main entity for this endpoint?
▶️ users
▶️ user_types
After choosing the table you will need to choose if the endpoint should be paginated or not.
Should GET endpoint be paginated?
▶️ Yes
▶️ No
Now You will have to select at least one column from your table to filter by, in this case, let's select user_id.
Select columns to filter (Must be atleast one filter for GET, PUT, DELETE)
(Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
◉ user_id
◯ first_name
◯ last_name
◯ email
◯ password
◯ user_type_id
◯ created_at
Now let's select the columns that will be included in the response from this endpoint.
Select columns for response
(Press <space> to select, <a> to toggle all, <i> to invert selection, and <enter> to proceed)
◉ user_id
◉ first_name
◉ last_name
◉ email
◉ created_at
◯ password
◯ user_type_id
In your routes.js
file a new route will be created, you can proceed to modify the created controller or add a middleware.
// routes.js
router.get("/users", /*- TODO: auth middleware -*/ getUsers);
✅ And DONE! Your endpoint has been successfully created. A new route, controller and action will be created.