sample-blog-api-go

command module
v0.0.0-...-cf27a83 Latest Latest
Warning

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

Go to latest
Published: May 27, 2023 License: MIT Imports: 10 Imported by: 0

README

Sample Blog API

tests Go Report Card Go Doc

A simple blog API written using go.

Install

go get github.com/akornatskyy/sample-blog-api-go

Run

cd $(go env GOPATH)/src/github.com/akornatskyy/sample-blog-api-go
go run main.go

Docker

docker run -it --rm -p 8080:8080 akorn/sample-blog-api-go

curl

Validation error:

$ curl -i -H 'Content-Type: application/json' -d '{}' \
  http://localhost:8080/signin

HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=UTF-8
Date: Thu, 22 Nov 2018 14:07:18 GMT
Content-Length: 265

{
  "errors": [{
      "domain": "signin",
      "type": "field",
      "location": "username",
      "reason": "required",
      "message": "Required field cannot be left blank."
    },
    {
      "domain": "signin",
      "type": "field",
      "location": "password",
      "reason": "required",
      "message": "Required field cannot be left blank."
    }
  ]
}

General error:

$ curl -i -H 'Content-Type: application/json' \
  -d '{"username":"js", "password": "password"}' \
  http://localhost:8080/signin

HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=UTF-8
Date: Thu, 22 Nov 2018 14:13:16 GMT
Content-Length: 167

{
  "errors": [{
    "domain": "signin",
    "type": "summary",
    "location": "user",
    "reason": "account locked",
    "message": "The account is locked. Contact system administrator, please."
  }]
}

Valid:

curl -i -H 'Content-Type: application/json' \
  -d '{"username": "demo", "password": "password"}' \
  http://localhost:8080/signin

HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
Date: Wed, 21 Nov 2018 10:12:05 GMT
Content-Length: 20

{"username":"demo"}

Documentation

Overview

A simple blog API.

Directories

Path Synopsis
shared
rule
Package rule contains validation rules that can be reused.
Package rule contains validation rules that can be reused.

Jump to

Keyboard shortcuts

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