- GET /swagger/index.html --> Gets the swagger documentation
- POST /api/v1/user/register --> Register end returns User. Uses username and password
- POST /api/v1/user/login --> Login and return User with the JWT token. Uses username and password
- POST /api/v1/endgame (Needs auth) --> Ends game for users and updates scores, return leaderboard.
- GET /api/v1/leaderboard (Needs auth) --> Gets leaderboard.
- Copy the JWT which came from
/register
response - Put header in the request as
Bearer <your token>
for the/endgame
and/leaderboard
APIs
git clone https://github.com/zgrgrcn/mageBATestCase
cd mageBATestCase
go run main.go
You don't need to have any local database, Thanks to Mongo Atlas! Create a .env file in the root directory and add the following lines:
DATABASE_URL=mongodb+srv://
TOKEN_KEY=key
PORT=:8080
go run main.go
The default port is 8080 go to http://localhost:8080/swagger/index.html or https://shielded-springs-54397.herokuapp.com/swagger/index.html to see swagger ui.
For /user endpoint you don't need to add any token, but for /leaderboard and /endgame endpoints you need to add a token to the header as Bearer. You can get token from /user/login endpoint.
There is a postman collection in the root directory of the project. You can import it to your postman and test the API. The file name is Mage.postman_collection.json.
Also, there are 25 test in the code. Current coverage rate is 87.9% of the statements.
All APIs are online(thanks to GitHub CI/CD and Heroku) and you can test them with swagger ui or postman collection. https://shielded-springs-54397.herokuapp.com/swagger/index.html (it is a free tier, so don't be surprised if it is slow)
For /user endpoint you don't need to add any token, but for /leaderboard and /endgame endpoints you need to add a token to the header as Bearer. You can get token from /user/login endpoint.
Generate Swagger Documentation (Needs to install swag, Docs already exist, so pass this step if you don't want to generate docs again)
swag init