This is a simple microservice example built with Node.js and Express.js. It exposes a RESTful API with various endpoints.
These instructions will help you get the microservice up and running on your local machine for development and testing purposes.
Make sure you have the following software installed on your machine:
- Node.js (version X.X.X or higher)
- npm (Node Package Manager)
-
Clone the repository to your local machine:
git clone https://github.com/DevSecOps-AppSec/nodejs-microservices.git
-
Navigate to the project directory:
cd nodejs-microservices
-
Install the dependencies:
npm install
To start the microservice, run the following command:
node server.js
The microservice will be running at http://localhost:3000
.
The microservice provides the following API endpoints:
- URL:
/api/greeting
- Method: GET
- Parameters:
name
(optional): The name to include in the greeting message. If not provided, the default value is "Anonymous".
- Response:
- Content-Type: application/json
- Body:
{ "message": "Hello, {name}!" }
Example request:
GET /api/greeting?name=John
Example response:
{
"message": "Hello, John!"
}
- URL:
/api/time
- Method: GET
- Response:
- Content-Type: application/json
- Body:
{ "time": "{current_time}" }
Example request:
GET /api/time
Example response:
{
"time": "12:34 PM"
}
- URL:
/api/users
- Method: GET
- Response:
- Content-Type: application/json
- Body:
{ "users": [ { "id": 1, "name": "John Doe" }, { "id": 2, "name": "Jane Smith" }, { "id": 3, "name": "Bob Johnson" } ] }
Example request:
GET /api/users
Example response:
{
"users": [
{ "id": 1, "name": "John Doe" },
{ "id": 2, "name": "Jane Smith" },
{ "id": 3, "name": "Bob Johnson" }
]
}
Contributions are welcome! If you find any issues or have suggestions for improvement, please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License.
- The microservice is based on the Express.js framework.
- Thanks to the Node.js and npm communities for their valuable packages.
Feel free to customize the README.md file further according to your specific requirements and project details.