This API allows you to manage person records in a MongoDB database using the Go programming language and the Gin web framework. You can perform basic CRUD (Create, Read, Update, Delete) operations on person records.
Before you begin, ensure you have met the following requirements:
- Go (Golang) installed on your system.
- MongoDB installed and running.
To set up the API, follow these steps:
-
Clone the repository to your local machine:
git clone https://github.com/usmahm/HNG_task_2
-
Change to the project directory:
cd HNG_task_2
-
Install the required Go packages using:
go get .
Before running the API, you need to configure your MongoDB connection settings. Add a .env
file with your MONGODB_URI gotten from your MongoDB database:
MONGODB_URI='Replace with URI from Mongodb'
To run the API, follow these steps:
-
Start your MongoDB server if it's not already running.
-
Run the following command from the project directory:
go run .
This will start the API server on port 8080 by default.
-
The API is now running and ready to accept requests.
The API provides the following endpoints:
GET /person/:param
: Retrieve a person record by ID or name.POST /person
: Create a new person record.PUT /person/:param
: Update an existing person record by ID or name.DELETE /person/:param
: Delete a person record by ID or name.
For detailed information on each endpoint, refer to the API Documentation.
The API returns appropriate HTTP status codes and error messages for different scenarios. Refer to the Error Handling section in the API Documentation for more details.