Giter Site home page Giter Site logo

api's Introduction

API

Simple proof of concept web-service / API in Go.

  1. API
    1. Requirements
    2. Installation
      1. Database setup
      2. Start the server
    3. Usage
      1. Error model
      2. Create
      3. Lookup
      4. List
      5. Health

Requirements

go: >= 1.15
postgresql >= 11.x

Installation

apt-get install postgresql postgresql-client
sudo -u postgres psql postgres

After dropping into the postgres shell change the password

#\password
Enter new password:
123456
\q

Database setup

export DB_HOST=localhost
export DB_PORT=5432
export DB_USER=postgres
export DB_PASSWORD=123456
export DB_NAME=test

Run go test in the storage package to initialize the database schema (see storage_test.go).

Start the server

make run

or equivalently

go run cmd/api/api.go

Usage

psql -U postgres -d test -a -f storage/00.sql 

Create

Create a product.

Example request

curl --header "Content-Type: application/json" \
	--request POST \
	--data '{"sku":"9a982384y932", "attrs":{"mass":"undefined"}}' \
    http://localhost:8080/product/create

Lookup

Lookup a product by SKU.

Example request

curl "http://localhost:8080/product/get?sku=9a982384y932" | jq

List

List products (paginated).

Example request

curl "http://localhost:8080/product/list?lo=0&hi=10" | jq

Delete

Delete a product

Example request

curl "http://localhost:8080/product/delete?sku=9a982384y932" | jq

### Health
The healthz endpoint returns the server's health status; when the server
is started if backing systems are unreachable, all other endpoints will
respond with `HTTP 503 ServiceUnavailable`

Example request
```sh
curl http://localhost:8080/healthz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.