PostWebApi is a .NET 9 Web API used to manage post related data in PostOShare. It depends on .NET 9 and communicates with a MongoDB database.
The following need to be available to ensure that the API and the Mongo DB database can be setup:
Additionally, it requires that IdentityWebApi is running. This requires that the following is available:
Steps that can be used to setup the API are
git clone https://github.com/PostOShare/PostWebApi.git
cd PostWebApi\PostWebApi
dotnet restoreBefore starting the API install the IdentityWebApi and execute this API. Then execute the PostWebApi.
- Microsoft.AspNetCore.Authorization
- Microsoft.AspNetCore.Authentication.JwtBearer
- Serilog.AspNetCore
- Serilog.Sinks.File
- Microsoft.Extensions.Http
- MongoDB.Bson
- Microsoft.AspNetCore.Http
- Microsoft.Extensions.Configuration.Abstractions
- MongoDB.Driver
These dependencies are used only in development:
- Swashbuckle.AspNetCore
- Swashbuckle.AspNetCore.Annotations
- Microsoft.AspNetCore.OpenApi
This endpoint is used to save a post to the database.
curl -X 'POST' \
'https://localhost:7005/api/v1/Post/create-post' \
-H 'accept: text/plain' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiJ1c2VyNCIsIm5iZiI6MTc5MTAzOTc2NywiZXhwIjoxNzkxMTI2MTY3LCJpYXQiOjE3OTEwMzk3NjcsImlzcyI6Imh0dHBzOi8vd3d3LnBvc3Rvc2hhcmUuY29tLyJ9.mIOdSBXYeNVsoSy6erHvmHW3GlQEoKWa0rvmytcHgBI" \
-d '{
"partitionKey": "user4",
"type": "post",
"content": "Look at this amazing sunset!",
"media": [
{
"type": "image",
"url": "https://cdn.myapp.com/blobs/sunset.jpg",
"createdAt": "2026/08/31 21:30:00",
"visibility": "public"
}
],
"createdAt": "2026/08/31 21:30:00",
"lastUpdatedAt": "2026/08/31 21:30:00",
"agent": "web",
"visibility": "public",
"stats": {
"thumbsUpReactions": 0,
"hahaReactions": 0,
"angryReactions": 0,
"loveReactions": 0,
"comments": 0,
"share": 0
},
"comments": [
{
"commentId": "c_001",
"userId": "user_456",
"text": "Sample text",
"createdAt": "2026/08/31 21:33:00",
"lastUpdatedAt": "2026/08/31 21:33:00",
"subComments": [
{
"subCommentId": "sc_001",
"userId": "user_123",
"text": "Sample text",
"createdAt": "2026/08/31 21:35:00",
"lastUpdatedAt": "2026/08/31 21:30:00"
}
]
}
]
}'
-
201 - Post inserted
{ "result": true, "errorDescription": "", "errorCode": "00000" } -
400 -
{ "type": "https://tools.ietf.org/html/rfc9110#section-15.5.1", "title": "One or more validation errors occurred.", "status": 400, "errors": { "PartitionKey": [ "partitionKey is required for Cosmos DB compatibility" ] }, "traceId": "00-c603c299c831b1043fe68ec409cb9d20-4e13003f77fb5e07-00" } -
500 -
{ "result": false, "errorCode": "", "errorDesc": "No connection could be made because the target machine actively refused it. (localhost:7224)", "posts": null }
