Giter Site home page Giter Site logo

ankurallin1 / gofr-project Goto Github PK

View Code? Open in Web Editor NEW
1.0 0.0 0.0 25 KB

A Go CRUD app using Fiber and MongoDB for simple student record management. Ideal for learning web development in Go.

Go 100.00%
crud go-framework go-testing gofiber golang mongodb test-automation testing

gofr-project's Introduction

Go CRUD Application with Fiber and MongoDB

The Go CRUD Application is a simple yet robust project built using the Fiber web framework and MongoDB database. It facilitates basic CRUD operations (Create, Read, Update, Delete) for managing student records. Fork, customize, and extend to meet your specific needs with the flexibility of Go and Fiber.

Table of Contents

Prerequisites

Before you begin, ensure you have the following installed on your machine:

Getting Started

  1. Clone the repository:

    git clone https://github.com/Ankurallin1/GOFR-Project
    
    cd GOFR-Project
  2. Download Dependencies:

    go mod download
    
  3. Verify Dependencies:

    cat go.sum
  4. Run Project

    go run main.go
    
  5. Open Server

    http://localhost:8080/students
    

API Endpoints

The application provides RESTful API endpoints for CRUD operations on student records.

Base URL

The base URL for all endpoints is:

List of Endpoints

1. Get All Students

  • Endpoint:

    • GET /students
  • Description:

    • Retrieves a list of all students.
  • Example Response:

    [    {      "id": "657ad262660b9c2342474c33",      "name": "ankur",      "email": "[email protected]",      "collegeName": "JUET",      "enrollmentNo": "201B049"    },    {      "id": "657be72ea13c844c358f83b2",      "name": "John Doe",      "email": "[email protected]",      "collegeName": "Sample College",      "enrollmentNo": "12345"    }  ]
    

Screenshot (17)

2. Get Student by ID

  • Endpoint:

    • GET /students/:id
  • Parameters:

    • id: The unique identifier for the student.
  • Description:

    • Retrieves information about a specific student based on the provided ID.
  • Example Response:

    [    {      "id": "657ad262660b9c2342474c33",      "name": "ankur",      "email": "[email protected]",      "collegeName": "JUET",      "enrollmentNo": "201B049"    }   ]  
    

Screenshot (18)

3. Create a New Student

  • Endpoint:

    • POST /students
  • Request Body:

    [    {      "name": "John Doe",      "email": "[email protected]",      "collegeName": "Sample College",      "enrollmentNo": "12345"    }   ]  
    
    
  • Description:

    • Creates a new student record.
  • Example Response:

    {      "id": "generated-student-id",      "name": "John Doe",      "email": "[email protected]",      "collegeName": "Sample College",      "enrollmentNo": "12345"    }
    
    

Screenshot (19)

4. Update Student by ID

  • Endpoint:

    • PUT /students/:id
  • Parameters:

    • id: The unique identifier for the student.
  • Request Body:

    [    {      "name": "Updated Name",      "email": "[email protected]",      "collegeName": "Updated College",      "enrollmentNo": "54321"    }   ]  
    
  • Description:

    • Updates information about a specific student based on the provided ID.
  • Example Response:

    "Student updated successfully"
    

Screenshot (21)

5. Delete Student by ID

  • Endpoint:

    • DELETE /students/:id
  • Parameters:

    • id: The unique identifier for the student.
  • Description:

    • Deletes a specific student record based on the provided ID.
  • Example Response:

    "Student deleted successfully"
    

Screenshot (20)

Automated Testing

The project includes test cases that can be executed using Go's testing framework.

Changes Required

  • Change the id in below lines of main_test.go :

    • Line 79 for UpdateStudent
      req := httptest.NewRequest(http.MethodPut, "/students/{id}", bytes.NewReader(updatedStudentJSON))
      
    • Line 91 for DeleteStudent
      req := httptest.NewRequest(http.MethodDelete, "/students/{id}", nil)
      
      

Running Tests

  • Use the following command to run the tests:

    go test
    
    
test

Sequence Diagram

sequence

UML Diagram

uml diagram

Contributing

Feel free to contribute to this project. Fork the repository, make your changes, and submit a pull request.

gofr-project's People

Contributors

ankurallin1 avatar

Stargazers

 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.