GithubHelp home page GithubHelp logo

go-rest-api's Introduction

GO-REST-API

Hello, I have created a simple Go project that uses Gofr, Gorm, and MySQL.

This project aims to create REST APIs for basic operations, including create, read, update, and delete. I have create simple example involving a student management using these operations to illustrate the use case.

This project can be consider for future modification for learning purpose where i can add more feature for a student such as subjects a student can have.

To test this project i have created a database locally using mysql cli with the following commands:

  1. create database students;

  2. use database students;

  3. CREATE TABLE students ( id INT PRIMARY KEY, name VARCHAR(255), class VARCHAR(50), age INT );

  4. After that i have used create API and generated students records.

Application Requirement

  1. Install Go version - 1.21.5 via
  1. Once installed, Please check via below command
    go version
  1. Install GoFr
    go get gofr.dev

Setup Project

  1. Clone the Project
   git clone <project_url>
   cd <project_directory>
  1. Install Dependencies (Make sure that Go and MySQL are installed on your computer)
     go mod tidy
  1. Create a Local MySQL Database
   mysql -u root -p
  1. Run the Program
   go run main.go
  1. Test with Postman

⚙Project-Structure and Setup

HTTP-Rest-API/
    ├── configs/
    │     └── .env
    │
    ├── handler/
    │     └── handler.go
    │
    ├── model/
    │     └── model.go
    │
    ├── datastore/
    │     ├── datastore.go
    │     └── interface.go
    │── test
    │    ├── datastore_test.go
    │    ├── handler_test.go
    |                 
    ├── main.go
    ├── go.mod

After our project is succesfully built we have run it with the command go run main.go and it then pops the result of successfully connected to the database. run ss

Unit Test

Then we have used postman and tested different apis that we have made, and got the output similar to the attached images below: create put SS get ss GET 1 delete ss

Diagrams

  1. Architecture DiagramArchitecture Diagram
  2. Sequence DiagramSequence Diagram

go-rest-api's People

Contributors

medani17 avatar

Watchers

 avatar

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.