Next.js Discord

Discord Forum

Naming convention for route handlers

Unanswered
ABUL KALAM posted this in #help-forum
Open in Discord
I am working with NextJS route handlers. I want to know what the convention is regarding naming endpoints.
For example: I have to make handlers for 5 operations.
1. Create a new user
2. Update a user using his/her primary key
3. Delete a user using his/her primary key
4. Fetch a user using his/her primary key
5. Fetch all users

One route configuration can be like:
app
|__ api
    |__ user
        |__ route.ts (create (POST), update (PUT), delete (DELTE), fetch all (GET))
        |__ [id]
            |__ route.ts (fetch using id (GET))

Is this route configuration good? SInce another configuration can be to use [id] handler for operations related to id i.e. update, delete and fetch a user.
Please give recommendation.

0 Replies