A postwitter-api Go (version 1.11.2) app, developed echo framework (version v3.1.0).
This app package include REST API's for user and their post management and it can be easily deployed to Heroku as it includes all requried configurations.
- This repo demonstrates the integeration of Go, Echo framwork with MySQL
- Its using JWT token verification for all internal calls issued on login
- Its fetching lists Post from MySQL database and display into pagination list
- It has proper echo framwork middleware and routs defined
REST API's has been deployed on this link: https://postwitter-api.herokuapp.com/
And its running interfaces are available at: https://postwitter-portal.herokuapp.com
https://postwitter-api.herokuapp.com/v1/swagger/index.html
Make sure you have Go and the govendor installed. It help to add any dependencies to application.
$ cd $GOPATH/src
$ mkdir postwitter-api
$ git clone git@github.com:abdulbasitmughal/postwitter-api.git
$ go run server.go
Output logs will show port number on which server is listening.
If your see port 5000 then it will available on localhost:5000.
Download and install the Heroku CLI. If you haven't already, log in to your Heroku account and follow the prompts to create a new SSH public key.
$ heroku login
Initialize a git repository in a new or existing directory
$ cd postwitter-api/
$ git init
$ heroku git:remote -a {remote-project-name}
Commit your code to the repository and deploy it to Heroku using Git.
$ git add .
$ git commit -am "make it better"
$ git push heroku master
There are total six API's incorporated to complete this assignment. Here are details:
- Signup (POST: https://postwitter-api.herokuapp.com/v1/signup)
curl -H "Content-Type: application/json" -X POST -d "{\"email\":\"basit10@gmail.com\",\"password\":\"asdf\"}" "https://postwitter-api.herokuapp.com/v1/signup"
# => {"id":15,"email":"basit10@gmail.com"}
- Login (POST: https://postwitter-api.herokuapp.com/v1/login)
curl -H "Content-Type: application/json" -X POST -d "{\"email\":\"basit@gmail.com\",\"password\":\"123\"}" "https://postwitter-api.herokuapp.com/v1/login"
# => {"id":2,"email":"basit@gmail.com","token":"eyJhbGciOiJIUzI1NiIsInRasdfCJ9.eyJlbWFpbCI6ImJhc2l0QGdtYWlsLmNvbSIsImV4cCI6MTU0MjYwNDAwOH0.uGRPdwxn4-7NzL1f9XOCr-v5sQySzSvwN78M9jGh6ZY","timetag":"2018-11-13 20:55:20"}
- Get User List (GET: https://postwitter-api.herokuapp.com/v1/users)
curl -H "Content-Type: application/json" -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImJhc2l0MUBnbWFpbC5jb20iLCJleHAiOjE1NDI1MTMwMjB9.TnxeVIhuVfpaD6d46tAVBsqVs3vx9PVmL6ExMvXiqug" -X GET "https://postwitter-api.herokuapp.com/v1/users"
# => {"user":[{"id":1,"email":"abdulbasitmughal@gmail.com","timetag":"2018-11-13 20:54:40"}]}
- Get User's Post (GET: https://postwitter-api.herokuapp.com/v1/users/:email/posts)
curl -H "Content-Type: application/json" -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImJhc2l0MUBnbWFpbC5jb20iLCJleHAiOjE1NDI1MTMwMjB9.TnxeVIhuVfpaD6d46tAVBsqVs3vx9PVmL6ExMvXiqug" -X GET "https://postwitter-api.herokuapp.com/v1/users/:email/posts?limit=5&page=1"
# => {"post":[{"id":0,"email":"basit1@gmail.com","Message":"test message1","TimeTag":"2018-11-16 09:33:34"},{"id":0,"email":"basit1@gmail.com","Message":"test message1","TimeTag":"2018-11-16 09:23:00"}]}
- Get User's Post Feed (GET: https://postwitter-api.herokuapp.com/v1/posts)
curl -H "Content-Type: application/json" -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImJhc2l0MUBnbWFpbC5jb20iLCJleHAiOjE1NDI1MTMwMjB9.TnxeVIhuVfpaD6d46tAVBsqVs3vx9PVmL6ExMvXiqug" -X GET "https://postwitter-api.herokuapp.com/v1/posts?page=1&limit=2"
# => {"post":[{"id":0,"email":"basit1@gmail.com","Message":"test message1","TimeTag":"2018-11-16 09:33:34"},{"id":0,"email":"basit1@gmail.com","Message":"test message1","TimeTag":"2018-11-16 09:23:00"}]}
- Create Post (POST: https://postwitter-api.herokuapp.com/v1/posts)
curl -H "Content-Type: application/json" -H "authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImJhc2l0MUBnbWFpbC5jb20iLCJleHAiOjE1NDI1MTMwMjB9.TnxeVIhuVfpaD6d46tAVBsqVs3vx9PVmL6ExMvXiqug" -X POST -d "{\"message\":\"test message\"}" "https://postwitter-api.herokuapp.com/v1/posts"
# => {"id":25,"email":"basit1@gmail.com","Message":"test message","TimeTag":"2018-11-16 10:21:36"}