This is an API built when I was learning Go. Here I am using 2 modules,
- (Gin)[github.com/gin-gonic/gin] - For quickly building the API
- (Colly)[github.com/gocolly/colly] - For web scrapping.
The API just hits the Goodreads quotes page and fires a search. It returns a list of Quotes with their authors. I have built it and deployed it on Heroku.
Commands I ran basically from start to finish
go mod init vigneshm.me/go-quotes-apiThis creates a file called go.mod. This has the name of the project and version of Go it uses.
go get github.com/gin-gonic/gin
go get github.com/gocolly/collyThis imports the modules, creates a go.sum file to add checksums for the modules it downloads.
Next, I filled in the main.go with my code.
Now, for the Heroku part.
npm install -g herokuheroku login -igit init
git add .
git commit -m "inital commit"touch Procfile
echo "web: bin/go-quotes-api" > ProcfileThis basically tells Heroku to run the command on startup.
heroku create go-quote-api
git push heroku masterThis create the Heroku app and pushes the code.
Heroku takes this code runs the build and exposes the app at https://.herokuapp.com/
My app is available at https://go-quote-api.herokuapp.com/quotes/dumbledore
The last word can be replaced with any search criteria to search for quotes from your favorite character or book.