This is a basic web service project built with native Node.js, without any external frameworks. It covers basic routing, handling different HTTP methods, and working with URL parameters and query strings. The goal of this project is to serve as a reference for anyone looking to understand how a web service can be written using just Node.js.
- Basic Routing: Set up routes for different endpoints.
- Route with Parameters: Handle dynamic routes with URL parameters.
- Query Parameters: Extract and process query strings from the URL.
- HTTP Methods: Support for common HTTP method:
GET
,POST
,PUT
,DELETE
Ensure you have Node.js installed on your machine.
- Clone the repository:
git clone https://github.com/FarrelAD/Basic-Web-Service-NodeJS.git
- Navigate into the project directory:
cd Basic-Web-Service-NodeJS
- Install any required dependencies (if applicable):
npm install
To start the web service, run the following command:
npm run start
The server will be running at http://localhost:5000
Here are the key endpoints that you can interact with:
GET / : Returns a simple welcome message and provide simple form to handle request input
GET /users : Fetch all users
GET /users/:id : Fetch a data by their ID
POST /users : Add a new user
PUT /users/:id : Update user information
DELETE /users/:id : Delete a user by their ID
GET /search?name=&job= : Retrieves data based on user input from a search form, filtering results by name and job
Example: /search?name=John&job=data+analyst Query parameters can be extracted and used in request processing.
The service supports the following HTTP methods:
GET: Retrieve data.
POST: Submit new data.
PUT: Update existing data.
DELETE: Remove data.
The project is simple and has the following structure:
/root
├─ index.js # Main server logic
└── /src
├─ /controller # A handler for any request
├─ /data # JavaScript object format to store dummy data
└─ /routes # Contains routing logic for different endpoints
This project is licensed under the MIT License.
This project is intended to help others learn the basics of building a web service with Node.js.