Categorygithub.com/tiagoc0sta/api-go-gin
repositorypackage
0.0.0-20240514045233-ebc20700b9d9
Repository: https://github.com/tiagoc0sta/api-go-gin.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Go: Developing a REST API - Gin and GORM

Acknowledgements

  • This is a project of creating a a REST API using Gin and GORM, connect it to a PostgreSQL database using a Docker image.

Authors

Requirements

  • Golang
  • PostgreSQL
  • Gin
  • GORM
  • Docker
  • Postman

Environment Variables

To run this project, you will need to do the following:

  • docker-compose up
  • go run main.go

Features

  • Access from postman
  • Create / update / edit / delete an item from a db using the frontend

Demo

Postgre database created via Docker

Postman - Perform CRUD tests via

image

View all API data on JSON format

image

Swagger - Framework for API documentation / testing

image

Frontend

  • image

Tests

Golang: Website Monitoring

Lessons Learned:

  • Understood the importance of structuring the API endpoints and handling HTTP requests and responses efficiently.

Integrating with a Database

  • Learned how to integrate a Go API with a database using Docker.

  • Gained knowledge of using Docker for containerization and database management. Using GORM

  • Learned how to use GORM, Go's popular ORM (Object-Relational Mapping) library, for database operations.

  • Explored features such as model definitions, querying, and relationships management provided by GORM.

Creating Middleware

  • Learned how to create middleware in Go to handle cross-cutting concerns such as logging, authentication, and request validation.
  • Understood the benefits of using middleware to avoid code duplication and maintain clean API logic.

Integrating with a React Frontend

  • Learned how to integrate a Go API with a React frontend for a full-stack application.
  • Explored methods for communication between the frontend and backend, such as RESTful APIs and WebSocket.

Installation

  1. Open Docker Desktop

  2. Run Docker

  docker-compose up
  1. Run API
  run main.go
  1. Open Postman and perform CRUD operations on API. See the reponse on the frontend

Notes:

Gin framework- to create API - Official site: https://github.com/gin-gonic/gin

Gorm ORM

PostgreSQL

  • Store data

Docker - create two images:

  • 1 postgres
  • 2 pgadmin-compose

Validator - V2 - https://pkg.go.dev/gopkg.in/validator.v2

gitignore file - Include all .yml filmes in gitignore in order to avoid sharing them to the cloud.

image

Render page on the FrontEnd

Github - provide project link

explain MVC model - Model View Controller