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.
- Prerequisites
- Getting Started
- API Endpoints
- Automated Testing
- Sequence Diagram
- UML Diagram
- Contributing
Before you begin, ensure you have the following installed on your machine:
-
Clone the repository:
git clone https://github.com/Ankurallin1/GOFR-Project cd GOFR-Project
-
Download Dependencies:
go mod download
-
Verify Dependencies:
cat go.sum
-
Run Project
go run main.go
-
Open Server
http://localhost:8080/students
The application provides RESTful API endpoints for CRUD operations on student records.
The base URL for all endpoints is:
-
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" } ]
-
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" } ]
-
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" }
-
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"
-
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"
The project includes test cases that can be executed using Go's testing framework.
-
Change the
id
in below lines ofmain_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)
- Line 79 for
-
Use the following command to run the tests:
go test
Feel free to contribute to this project. Fork the repository, make your changes, and submit a pull request.