Simple REST APIs with database firebase cloud firestore
- Go 1.20 or higher
- JWT Authorization
- Cloud Firestore Database
Follow these steps to run the project:
-
Create a Cloud Firestore database by following this Guide.
-
Export your service account credentials on the project settings in the Firebase console. Download the service-account JSON file and place it in the credentials folder:
rest-api-go-firestore/config/credential/sa-{YOUR_GO_ENV}.json
. -
Run the application using the following command:
go run ./cmd/app.go
Retrive auth token expires in 1 hour
- api/token?client_id=sample&client_secret=BiquzG0JVY3pWPrh8xiVPkbNXyx20Gmn
- Response :
{
"status": 200,
"message": "Token generated successfully",
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"type": "Bearer"
}
}
Retrive specific user data
- api/users/:docRefID
- Header :
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
- Response :
{
"status": 200,
"message": "User data retrieved successfully",
"data": {
"docRefId": "iCOmqSXxG8bJZfVJ8iuj",
"firstName": "Gerald",
"lastName": "Fisher",
"username": "BettyHolmes",
"email": "quia@Flipopia.name",
"ccNumber": "4916791396904137",
"ccType": "Discover",
"country": "Uruguay",
"city": "Santa Monica",
"currency": "Albania Leke"
}
}
Retrive all users data
- api/users
- Header :
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
- Response :
{
"status": 200,
"message": "Users data retrieved successfully",
"data": [
{
"docRefId": "76KbFdZd8kVCawLNBUle",
"firstName": "Debra",
"lastName": "Washington",
"username": "eum_quia",
"email": "ipsam_ex@Aivee.org",
"ccNumber": "5237378900055256",
"ccType": "VISA",
"country": "Dominican Republic",
"city": "Orinda",
"currency": "Jordan Dinars"
},
{
"docRefId": "M0tbZqmFkS3J42xWJ697",
"firstName": "Ashley",
"lastName": "Hamilton",
"username": "hNguyen",
"email": "cHunter@Zoonoodle.com",
"ccNumber": "379957517654574",
"ccType": "MasterCard",
"country": "Kazakhstan",
"city": "Ione",
"currency": "United Kingdom Pounds"
},
{
"docRefId": "XeidVNtUgURCANof8jxc",
"firstName": "James",
"lastName": "Powell",
"username": "mollitia",
"email": "uOliver@Vipe.biz",
"ccNumber": "5347663249612785",
"ccType": "Discover",
"country": "Niue",
"city": "Ione",
"currency": "Bahrain Dinars"
}
]
}
Create new user
- api/users
- Header :
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
- Body :
{
"FirstName": "James",
"LastName": "Powell",
"Username": "mollitia",
"Email": "uOliver@Vipe.biz",
"CCNumber": "5347663249612785",
"CCType": "Discover",
"Country": "Niue",
"City": "Ione",
"Currency": "Bahrain Dinars"
}
- Response :
{
"status": 201,
"message": "User data inserted successfully",
"data": {
"docRefID": "DYyDOPZ8nJzZWB7Y965J"
}
}
Update specific user data
- api/users/:docRefID
- Header :
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
- Body :
{
"firstName": "James",
"lastName": "Powell",
"username": "mollitia",
"email": "uOliver@Vipe.biz",
"ccNumber": "5347663249612785",
"ccType": "Discover",
"country": "Niue",
"city": "Ione",
"currency": "Bahrain Dinars"
}
- Response :
{
"status": 200,
"message": "User data updated successfully"
}
Delete specific user data
- api/users/:docRefID
- Header :
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
- Response :
{
"status": 200,
"message": "User data deleted successfully"
}