Skip to content

ericz99/go-server-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Server REST API Example

A RESTful API example for simple book application in Golang

Installation & Run

# Download this project
go get github.com/ericz99/go-server-api

Before running API server, you should set the database config with yours or set the your database config with my values on config.go

Also, please change .env.example -> .env and update the all fields.

# production env mode
mode = development

# database config
db_name = testdb
db_pass = passwrod
db_user = root
db_type = mysql
db_host = localhost
db_port = 3306

# server port
port = 8080

# for jwt secret key
secret_key = feTATm1?@d+1GKG
# Build and Run
cd go-server-api
go build
./go-server-api - [if you\'re using linux/macos]
go-server-api - [if you\'re using windows]

# API Endpoint (VERSION 1) : http://localhost:8080/api/v1
# API Endpoint (VERSION 2) : http://localhost:8080/api/v2
# API Auth Endpoint : http://localhost:8080/api/auth

API

Auth Endpoint - Using auth endpoint

/register

  • POST : Create new user

#Post Params

{
	"name": "Hello World",
	"email": "test@yahoo.com",
	"password": "asdfasdf"
}

/login

  • POST : Login User

#Post Params

{
	"email": "test@yahoo.com",
	"password": "asdfasdf"
}

Protected Endpoint - Using either V1 or V2 endpoint

Please add x-auth-token in your header in order to get authorized to any of these endpoint below!

/book/save

  • POST : Save a book

/books

  • GET : Get all book

/book/:id

  • GET : Get a book
  • DELETE : Delete a book

#Post Params

{
	"title": "LOL: Book PT 2",
	"isbn": "isbn-6s9",
	"author": {
		"name": "Bob"
	}
}

Todo

  • Support basic REST APIs.
  • Support GORM/Database
  • Support Authentication with user for securing the APIs.
  • Make convenient wrappers for creating API handlers.
  • Write the tests for all APIs.
  • Organize the code with packages
  • Make docs with GoDoc
  • Building a deployment process