Skip to content

Golang REST API example app using gorilla mux, mysql and http package in go

Notifications You must be signed in to change notification settings

ric-v/golang-rest-api-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

golang-rest-api-demo

This is an example application for REST APIs in golang with gorilla mux router and http package from standard library. The storage used is MySQL.

API documentation


  • ANY /

    • homepage with this info
  • GET /articles

    • retrives all articles from DB
    • query params : id (last ID from previous GET call for pagination), limit (max entry per page)
    • response : list of articles
  • POST /article

    • Add new article to DB
    • payload :
          {
              "Title"     (string)
              "desc"      (string)
              "content"   (string)
          }
  • PUT /article/{id}
    • Update an existing article DB
    • query param : id (article id from GET API)
    • payload :
          {
              "Title"     (string)
              "desc"      (string)
              "content"   (string)
          }
  • DELETE /article/{id}

    • Deletes an entry from DB
    • query param : id (article id from GET API)
  • GET /article/{id}

    • Retrieves article data from DB for a given ID
    • query param : id (article id from GET API)

Installation

installing and running mysql

docker run --name mysql-instance -p 3306:3036 -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql

docker exec -it mysql-instance -p 5432:5432 mysql -u myuser -p

installing running psql

docker run --name postgres-instance -e POSTGRES_PASSWORD=mysecretpassword -d postgres

docker exec -it some-postgres psql -U postgres

create new table

CREATE TABLE articles(
  id INTEGER PRIMARY KEY,
  title TEXT,
  descr TEXT,
  content TEXT
)

run the main.go file from the cloned repo to get access to REST APIs.

About

Golang REST API example app using gorilla mux, mysql and http package in go

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages