Skip to content

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

Notifications You must be signed in to change notification settings

Ankurallin1/GOFR-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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": "ankursri@gmail.com",      "collegeName": "JUET",      "enrollmentNo": "201B049"    },    {      "id": "657be72ea13c844c358f83b2",      "name": "John Doe",      "email": "john.doe@example.com",      "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": "ankursri@gmail.com",      "collegeName": "JUET",      "enrollmentNo": "201B049"    }   ]  
    

Screenshot (18)

3. Create a New Student

  • Endpoint:

    • POST /students
  • Request Body:

    [    {      "name": "John Doe",      "email": "john.doe@example.com",      "collegeName": "Sample College",      "enrollmentNo": "12345"    }   ]  
    
    
  • Description:

    • Creates a new student record.
  • Example Response:

    {      "id": "generated-student-id",      "name": "John Doe",      "email": "john.doe@example.com",      "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": "updated.email@example.com",      "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.

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages