Skip to content

a2rp/express-project-03-route-params-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-project-03-route-params-api

A simple Express.js backend project demonstrating how to use route parameters in an API.

Concept

This project shows how dynamic route parameters work in Express.js using the following pattern:

/users/:id

The id is captured from the URL and accessed using:

req.params.id

Tech Stack

  • Node.js
  • Express.js

Project Structure

express-project-03-route-params-api
│
├─ src
│  ├─ controllers
│  │  └─ user.controller.js
│  │
│  └─ routes
│     └─ user.routes.js
│
├─ index.js
├─ package.json
└─ .gitignore

Installation

Clone the repository

git clone https://github.com/a2rp/express-project-03-route-params-api.git
cd express-project-03-route-params-api

Install dependencies

npm install

Run the Server

node index.js

Server runs at:

http://localhost:3000

API Endpoint

Get User by ID

GET /users/:id

Example:

http://localhost:3000/users/25

alt text

Response:

{
    "id": "25",
    "name": "User 25",
    "message": "User data fetched successfully for id 25"
}

Learning Outcome

This project demonstrates:

  • Express route parameters
  • Dynamic API routes
  • Controllers and route separation
  • Basic backend architecture

Author

Ashish Ranjan


Follow me:

About

Express.js API demonstrating dynamic route parameters using /users/:id.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors