AppointyTask API
How to Compile
- Export All the required environment variables.
MONGO_URI = Database URI
PORT = Port to run the server on
DATABASE_NAME = Database name
- Navigate to api directory and Run the command.
go run main.go
- The server will be running on the port specified using the environment variable PORT.
- The API will through an runtime error if the environment variables are not set.
Details About the Endpoints
- [ POST ] /users: To create a new user.
Checks if the user already exists in the database. If the user does not exist, creates a new user.
Request Body:
{
"_id" : string, //Later Converted to Mongo ObjectId
"name" : string,
"username" : string,
"password" : string,
}
- [ GET ] /users/{id}: To get a user by id.
Returns the user with the given id.
Request Body:
{
"_id" : string, //Later Converted to Mongo ObjectId
"name" : string,
"username" : string,
"password" : nil,
}
- [ POST ] /posts: To create a new post.
Creates a new post.
Response :
{
"_id" : string, //Later Converted to Mongo ObjectId
"caption" : string,
"imageurl" : string,
"postedat" : string,
"userid" : mongo.ObectjId,
}
- [ GET ] /posts/{id}: To get a post by id.
Returns the post with the given id.
Response :
{
"_id" : string, //Later Converted to Mongo ObjectId
"caption" : string,
"imageurl" : string,
"postedat" : string,
"userid" : mongo.ObectjId,
}
- [ GET ] /posts/users/{uid}: To get all posts by userid.
For the specified userid, returns the posts of the user based on Page No. and Page Limit.
Request Body:
{
"page" : int,
"limit" : int,
}
Response :
[{
"_id" : string, //Later Converted to Mongo ObjectId
"caption" : string,
"imageurl" : string,
"postedat" : string,
"userid" : mongo.ObectjId,
}, Upto the Page Limit or till the end of the posts]