This project allows you to dynamically create, manage, and utilize routes with specified actions and types.
- Install Node.js (version 12.x or above).
- Clone the repository:
git clone https://github.com/shiva-rockers/dynamic-routing.git
- Install dependencies:
npm install
- Set up the
.env
file in the root directory. Refer to.env.example
for guidance. - Start the server:
npm start
- API Documentation: Follow the Postman documentation for detailed working on routes here.
- Payload:
{ action, type, ...dynamic_params }
Define the main action for the route. Supported values:
register-route
: Creates a new route in memory.unregister-route
: Deletes the route from memory.re-register-route
: Deletes the existing route and creates a new one in memory.list-registered-routes
: Lists all the registered routes.
Define the action of the dynamically created route. Supported values:
download-file
: Downloads files stored in the public directory.create-user
: Creates a new user in the MongoDB database.append-params
: Appends parameters in the form of a response.
Step 1 - Register Route
- Endpoint: POST
localhost:8000/route/hello
- Payload:
{ "action": "register-route", "type": "append-params" }
Step 2 - Hit the Dynamic Route
- Endpoint: GET
localhost:8000/route/hello
- Payload:
{ "name": "<NAME>" }
Step 1 - Register Route
- Endpoint: POST
localhost:8000/route/download-file
- Payload:
{ "action": "register-route", "type": "download-file" }
Step 2 - Hit the Dynamic Route
- Endpoint: POST
localhost:8000/route/download-file
- Payload:
{ "fileName": "<FILE_NAME>" }
Step 1 - Register Route
- Endpoint: POST
localhost:8000/route/create-user
- Payload:
{ "action": "register-route", "type": "create-user" }
Step 2 - Hit the Dynamic Route
- Endpoint: POST
localhost:8000/route/create-user
- Payload:
{ "username": "<USER_NAME>", "email": "<EMAIL>" }