This is a basic RESTful API server, build with Golang. In this API server I have implemented Cobra CLI for running the API from the CLI and also used go-chi instead of Go net/http.
git clone git@github.com:Neaj-Morshad-101/HTTP-API-server.git
cd go/src/github.com/Neaj-Morshad-101/HTTP-API-server/
./HTTP-API-server start -p 8080
Notes: You can give any port number just remember this to use it in request you send.
postman
curl -X POST -d '{"username":"Neaj Morshad","password":"1234"}' http://localhost:8080/login
Notes: You can do it from the postman also, select verb POST and hit http://localhost:8080/login in the body section: select raw and the these login data in json format
{ "username" : "Neaj Morshad", "password" : "1234" }
TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiTmVhaiBNb3JzaGFkIl0sImV4cCI6MTY3OTY0MjIxOX0.RMoAGj7KGFUtvq3ebpg_3ksQJqy4Q-gA5jAfOF4SCPQ"
Notes: You will find this token in response section (Cookies) in Posman. Name: jwt Value: TOKEN For the posman you don’t have to set any thing. Go to bash, bacause ‘=’ is not supported in fish
curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" http://localhost:8080/albums
Notes: You can hit the API using postman also, Select correct verb and the API endpoints (GET, PUT, POST, DELETE)
- Start the API in default port : 8080 by
HTTP-API-server start
- Start the API in your given port by
HTTP-API-server start -p=PORT_NUMBER
, give your port number in the place of PORT_NUMBER
{ "Neaj Morshad", "1234", }
docker build -t <image_name> .
- or
docker build -t <docker_hub_username>/<image_name>:<tag> .
(if your do this then don't need to give tag before dockerhub push)
docker build -t neajmorshad/http-api-server:0.0.1 .
docker push neajmorshad/http-api-server:0.0.1
docker run -p 8080:8080 <image_name>
(valid when usedCMD ["start", "-p", "8080"]
in Dockerfile)docker run -p 8080:8080 <image_name> start -p "8080"
(when did not used CMD in Dockerfile)
Upload the image to Docker Hub
docker login --username=<docker_hub_username>
docker tag <id_of_the_created_image> <docker_hub_username>/<name_of_the_image>:<tag>
docker push <docker_hub_username>/<name_of_the_image>:<tag>
docker run -v <absolute_host_path/.env>:<container_path/.env> -p 8080:8080 <image_name> start -p 8080
WILL BE UPDATED SOON
WILL BE UPDATED SOON
- implemented JWT authentication
- first of all user need to hit
/login
endpoint with basic authentication then a token will be given and with that token for specific amount of time user can do other request
curl -X POST -H "Content-Type:application/json" -d '{"username":"neajmorshad","password":"1234"}' http://localhost:8080/login
- Primarily tested the API endpoints by Postman
- E2E Testing.
- Checked response status code with our expected status code