- Summary
- Getting started
- Prerequisites
- Packages
- Tools
- Features
- UML Diagram
- Running
- Logs
- Postman collection
Simple web service responding to requests with a greeting message. The service is written in Golang.
Clone the repository.
Follow the instructions to complete the installation.
- Upon startup read the HTTP port to listen on from command line arguments and it uses a default value 8080 if command line argument is not specified. For example:
go run main.go --port=9999 #application will run on port 9999
go run main.go #application will run on port 8080
- The webservice have one end point (/greet) that accept POST request with JSON payload looking like this:
{
"name" : "Sherif"
}
and it parses the JSON request and upon success respond with HTTP status 200 OK and a JSON body that looks like this:
{
"message": "Hello Sherif!"
}
- The webservice responses with HTTP status 405 (Method Not Allowed) if the request method on /greet is anything other than POST.
- The webservice responses with HTTP status 400 (Bad Request) for any incorrect requests on the /greet endpoint (for example the payload is not valid JSON, the Content-Type header is not application/json or the name property is missing).
- The webservice responses with HTTP status 404 (Not Found) on any URL other than /greet.
- The service handles SIGINT or SIGTERM signals (kill command on Linux or Ctrl+C on both Windows and Linux) and exit gracefully.
- In your cloned directory.
- open your terminal and run:
go run main.go
The server will start by default at:
- Local: http://localhost:8080
You can specify port number by passing it as an argument:
go run main.go --port=9999 #application will run on port 9999
After running the server, logs.txt file will be created in the root directory of the project. It will contain the logs.
you will find the postman collection here.
You can get what is the right structure of JSON file to send requests and receiving responses from the postman collection after importing it in the Postman.