This API provides endpoints for managing user data, including retrieving user information based on user IDs. It is built using Go and MongoDB.
- Go: Programming language used for implementing the API.
- Gin: Web framework for Go, used for routing and handling HTTP requests.
- MongoDB: NoSQL database used for storing user data.
- Go Modules: Dependency management for Go projects.
Retrieve a user's details by their unique user ID.
- URL:
/user/{user_id}
- Method:
GET
- URL Params:
user_id
(required): The unique ID of the user you want to retrieve.
- Success Response:
- Code: 200 OK
- Content:
{ "id": "66c8873ff32116292fe6ed03", "firstName": "John", "lastName": "Doe", "password": "$2a$14$ck73JJdzsOmQp2NCmaar1uQdn.FzpK9Z6qNYrRnNycIPv0Kmo7oha", "email": "john.doe@example.com", "phone": "1234567890", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "userType": "ADMIN", "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "createdAt": "2024-08-23T12:55:30Z", "updatedAt": "2024-08-23T13:01:19.537Z", "userId": "66c886c22f822334952ddbc9" }
Retrieve a list of all users.
- URL:
/users
- Method:
GET
- Success Response:
- Code: 200 OK
- Content:
{ "total_count": 3, "user_items": [ { "id": "66c886c22f822334952ddbc9", "createdAt": "2024-08-23T12:55:30Z", "email": "john.doe@example.com", "firstName": "John", "lastName": "Doe", "password": "$2a$14$ck73JJdzsOmQp2NCmaar1uQdn.FzpK9Z6qNYrRnNycIPv0Kmo7oha", "phone": "1234567890", "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "updatedAt": "2024-08-23T12:55:30Z", "userId": "66c886c22f822334952ddbc9", "userType": "ADMIN" }, { "id": "66c886c22f822334952ddbc9", "createdAt": "2024-08-23T12:55:30Z", "email": "john.doe@example.com", "firstName": "John", "lastName": "Doe", "password": "$2a$14$ck73JJdzsOmQp2NCmaar1uQdn.FzpK9Z6qNYrRnNycIPv0Kmo7oha", "phone": "1234567890", "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "updatedAt": "2024-08-23T12:55:30Z", "userId": "66c886c22f822334952ddbc9", "userType": "ADMIN" }, { "id": "66c886c22f822334952ddbc9", "createdAt": "2024-08-23T12:55:30Z", "email": "john.doe@example.com", "firstName": "John", "lastName": "Doe", "password": "$2a$14$ck73JJdzsOmQp2NCmaar1uQdn.FzpK9Z6qNYrRnNycIPv0Kmo7oha", "phone": "1234567890", "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...", "updatedAt": "2024-08-23T12:55:30Z", "userId": "66c886c22f822334952ddbc9", "userType": "ADMIN" } ] }
- Go (1.16 or higher)
- MongoDB
- Clone the repository:
git clone https://github.com/your-repo/go-user-api.git
- Navigate to the project directory:
cd go-user-api
- Install dependencies:
go mod tidy
-
Create a
.env
file in the root directory of the project with the following content:MONGO_URI=mongodb://localhost:27017
-
Ensure MongoDB is running and accessible at the specified URI.
Start the server with:
go run main.go