/Rest-API-Go-Example

Rest API example using gorm

Primary LanguageGo

API Reference

A restful API example using Gorm (ORM) and postgreSQL. The purpose for which I made this API was just for practice

General Table Views

Logo

Category Endpoints

  GET /api/v1/category/
  GET /api/v1/category/:id
  POST /api/v1/category/
  PATCH /api/v1/items/:id
  DELETE /api/v1/items/:id

Customer Endpoints

  GET /api/v1/customer/
  GET /api/v1/customer/:id
  POST /api/v1/customer/
  POST /api/v1/customer/:id
  PATCH /api/v1/customer/:id
  DELETE /api/v1/customer/:id

Product Endpoints

  GET /api/v1/product/
  GET /api/v1/product/:id
  POST /api/v1/product/
  PATCH /api/v1/product/:id
  DELETE /api/v1/product/:id

Configurations

Create a .env file, inside export URL connection where "market" is the database name.

export DATABASE_URI_DEV="postgres://postgres:root@localhost:5432/market?sslmode=disable"

before run migrations, make you sure to create the database on your database engine.

Logo

Migrations

Inside server.go, uncomment the method "StartMigrations()"

//initial migrations
connection.StartMigrations()

Run it once

go run ./server.go

Logo

if you do the above settings correctly, everything should be fine, now if you look the database engine you'll see the migrated tables (Comment again "StartMigrations()" method).

Tools used