It is POC to create web apis using golang

Overview

Web API using golang

It is POC to create web apis using golang. It is not using a good architecture like hexagonal archicture. But, it contains a CRUD using PostgreSQL and Migrations.

Used packages

  • gorm.io/gorm
  • github.com/gin-gonic/gin
  • gorm.io/driver/postgres

How to run

I'll assume that you have docker installed on your local machine. Therefore, you must execute the command:

docker-compose up --build

Then, you can execute the API:

go run main.go

It is necessary to have golang installed as well

Documentation

Create

curl --location --request POST 'http://localhost:5000/api/v1/users' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "Wagner"
}'

You will receive:

{
    "id": 1,
    "name": "Wagner",
    "created": "2021-08-05T10:17:50.026339526-07:00",
    "updated": "2021-08-05T10:17:50.026339526-07:00",
    "deleted": null
}

Get by ID

curl --location --request GET 'http://localhost:5000/api/v1/users/1'

You will receive:

{
    "id": 1,
    "name": "Wagner",
    "created": "2021-08-05T10:56:32.197227-07:00",
    "updated": "2021-08-05T10:56:32.197227-07:00",
    "deleted": null
}

Get all

curl --location --request GET 'http://localhost:5000/api/v1/users'

You will receive:

[
    {
        "id": 1,
        "name": "Wagner",
        "created": "2021-08-05T10:17:50.026339-07:00",
        "updated": "2021-08-05T10:17:50.026339-07:00",
        "deleted": null
    }
]

Update

curl --location --request PATCH 'http://localhost:5000/api/v1/users' \
--header 'Content-Type: application/json' \
--data-raw '{
    "id": 1,
    "name": "Wagner marques"
}'

You will receive

{
    "id": 1,
    "name": "Wagner marques",
    "created": "2021-08-05T10:56:32.197227-07:00",
    "updated": "2021-08-05T10:56:32.197227-07:00",
    "deleted": null
}

Delete

curl --location --request DELETE 'http://localhost:5000/api/v1/users/1'

You will receive a status 204

How to improve

The update endpoint is receiving the ID in the request body. Try to change it and send the user id using the request path. ;)

You might also like...
The jin is a simplified version of the gin web framework that can help you quickly understand the core principles of a web framework.

jin About The jin is a simplified version of the gin web framework that can help you quickly understand the core principles of a web framework. If thi

A powerful go web framework for highly scalable and resource efficient web application

webfr A powerful go web framework for highly scalable and resource efficient web application Installation: go get -u github.com/krishpranav/webfr Exa

A powerful go web framework for highly scalable and resource efficient web application

A powerful go web framework for highly scalable and resource efficient web application

Chainrand contract + web frontend + web backend

Chainrand-web This repo contains the implementation of Chainrand. https://chainrand.io Smart Contract Contains functionality to tie a Chainlink VRF to

A REST web-service sample project written in Golang using go-fiber, GORM and PostgreSQL

backend A REST web-service sample project written in Golang using go-fiber, GORM and PostgreSQL How to run Make sure you have Go installed (download).

Web framework for creating apps using Go in Google AppEngine

Welcome to app.go v3.0 app.go is a simple web framework for use in Google AppEngine. Just copy the app folder to your working folder and import it fro

package for building REST-style Web Services using Go

go-restful package for building REST-style Web Services using Google Go Code examples using v3 REST asks developers to use HTTP methods explicitly and

skr: The lightweight and powerful web framework using the new way for Go.Another go the way.
skr: The lightweight and powerful web framework using the new way for Go.Another go the way.

skr Overview Introduction Documents Features Install Quickstart Releases Todo Pull Request Issues Thanks Introduction The lightweight and powerful web

Owner
Wagner Marques
Desenvolvedor Back-End
Wagner Marques
A web app built using Go Buffalo web framework

Welcome to Buffalo Thank you for choosing Buffalo for your web development needs. Database Setup It looks like you chose to set up your application us

Mike Okoth 0 Feb 7, 2022
SendGrid's Golang HTTP Client for calling APIs

Quickly and easily access any RESTful or RESTful-like API. If you are looking for the SendGrid API client library, please see this repo. Announcements

Twilio SendGrid 161 Sep 25, 2022
⚓️ Golang RESTful APIs

Golang RESTful Golang RESTful API started on January 23rd, 2022. 环境配置相关解决办法

Hou Wenbo 0 Jan 23, 2022
Generate boilerplate + endpoints for Fiber REST APIs.

gomakeme Generate boilerplate + endpoints for Fiber REST APIs. Never spend 6 minutes doing something by hand when you can spend 1 week to automate it

null 4 May 9, 2022
Flamingo Framework and Core Library. Flamingo is a go based framework for pluggable web projects. It is used to build scalable and maintainable (web)applications.

Flamingo Framework Flamingo is a web framework based on Go. It is designed to build pluggable and maintainable web projects. It is production ready, f

Flamingo 317 Sep 27, 2022
⚡ Rux is an simple and fast web framework. support middleware, compatible http.Handler interface. 简单且快速的 Go web 框架,支持中间件,兼容 http.Handler 接口

Rux Simple and fast web framework for build golang HTTP applications. NOTICE: v1.3.x is not fully compatible with v1.2.x version Fast route match, sup

Gookit 81 Jul 20, 2022
Golanger Web Framework is a lightweight framework for writing web applications in Go.

/* Copyright 2013 Golanger.com. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except

golanger 299 Mar 3, 2022
re:Web enables classic web applications to run on AWS Lambda.

re:Web re:Web enables classic web applications to run on AWS Lambda. re:Web interfaces with the Lambda Runtime API. It translates API Gateway requests

null 102 Aug 16, 2022
henrylee2cn 1.6k Sep 16, 2022
Roche is a Code Generator and Web Framework, makes web development super concise with Go, CleanArch

It is still under development, so please do not use it. We plan to release v.1.0.0 in the summer. roche is a web framework optimized for microservice

Riita 14 Sep 19, 2022