basic-rest-example

module
v0.0.0-...-a551046 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2022 License: MIT

README

Golang basic REST api example

CI

Is a basic example how you can build a simple REST API in Go with go-chi and zap.

Based on https://github.com/golangdk

Used Packages

Environment Variables

In this example we use some different ENV vars:

Name HOST PORT APP_ENV
Default localhost 8000 develop

Features

  • Basic RST-API with go-chi
  • Singleton logger
  • Request & Response Examples
  • validation against post requests
  • mask of personal information in response

Prerequisite

  • golang >= 1.19.x

How to run

git clone git@github.com:bastian-kurz/go-basic-rest-example.git && cd go-basic-rest-example
HOST=localhost PORT=8081 go run cmd/server/main.go

or

make start

Endpoints

## Get specific user
GET http://localhost:8081/api/user/10
Accept: application/json

###
## Get a list of user
GET http://localhost:8081/api/user
Accept: application/json

###
## Valid Request

POST http://localhost:8081/api/user
Content-Type: application/json

{
  "userName": "doe",
  "email": "john.doe@testsubject.de",
  "firstName": "John",
  "lastName": "Doe",
  "password":"foobar"
}

###
## Invalid Request

POST http://localhost:8081/api/user
Content-Type: application/json

{
  "userName": "!!",
  "email": "john.doe@@@testsubject.de",
  "firstName": "John",
  "lastName": "Doe13",
  "password":"foobar"
}

###

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL