Simple blog implementation that uses ASP.NET Core to create an API that follows REST rules.
Features:
- Global Error Handling
- Validation
- Asynchronus Code
- Action Filters
- Model Binding
- Swagger Documentation
- DTOs
The API has 3 controllers:
- Categories
- Posts
- Comments
Method | Route |
---|---|
GET | api/categories |
GET | api/categories/{categoryId} |
GET | api/categories/({ids}) |
POST | api/categories |
POST | api/categories/collection |
PUT | api/categories/{categoryId} |
PATCH | api/categories/{categoryId} |
DELETE | api/categories/{categoryId} |
Method | Route |
---|---|
GET | api/posts |
GET | api/categories/{categoryId}/posts |
GET | api/posts/{postId} |
GET | api/posts/collection/{ids} |
POST | api/categories/{categoryId}/posts |
POST | api/categories/{categoryId}/posts/collection |
PUT | api/post/{postId} |
PATCH | api/post/{postId} |
DELETE | api/posts/{postId} |
Method | Route |
---|---|
GET | api/posts/{postId}/comments |
GET | api/posts/{postId}/comments/{commentId} |
GET | api/posts/{postId}/comments/collection/({ids}) |
POST | api/posts/{postId}/comments |
PUT | api/posts/{postId}/comments/{commentId} |
PATCH | api/posts/{postId}/comments/{commentId} |
DELETE | api/posts/{postId}/comments/{commentId} |
Get a list of all categories
Code | Description |
---|---|
200 | Returns the categories list |
Creates a new category
Code | Description |
---|---|
201 | Returns a newly created category |
400 | Category input object sent from client is null |
422 | Invalid model state for the category input object |
Get the category by id
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
categoryId | path | Category id | Yes | integer |
Code | Description |
---|---|
200 | Returns the category found by id |
404 | The category does not exist |
Deletes a category by id
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
categoryId | path | Category id | Yes | integer |
Code | Description |
---|---|
204 | Returns 204 no content response |
404 | The category does not exist |
Update the whole category by id
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
categoryId | path | Category id | Yes | integer |
Code | Description |
---|---|
200 | Returns 204 no content response |
400 | Category input is null |
404 | The category does not exist |
422 | Invalid model state for the category input |
Partially update category by id
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
categoryId | path | Category id | Yes | integer |
Code | Description |
---|---|
204 | Returns 204 no content response |
400 | Category input object sent from client is null |
404 | Category does not exist |
422 | Invalid model state for the category input object |
Get a list of categories by ids
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
ids | query | A comma-separated string of integers | Yes | [ integer ] |
Code | Description |
---|---|
200 | Returns the categories found by ids |
400 | Parameter ids is null |
404 | Some ids are not valid in a collection |
Creates multiple new categories
Code | Description |
---|---|
201 | Returns newly created categories |
400 | Categories collection input object sent from client is null |
422 | Invalid model state for the category input object |
Get a list of comments from a specific post
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
postId | path | Post id | Yes | integer |
Code | Description |
---|---|
200 | Returns the comments |
404 | The post does not exist |
Create comment for post
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
postId | path | Post id | Yes | integer |
Code | Description |
---|---|
201 | Returns the newly created comment |
400 | Comment input object is null |
404 | Post does not exist |
422 | Invalid model state for comment input object |
Get a specific comment from a specific post
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
postId | path | Post id | Yes | integer |
commentId | path | Comment id | Yes | integer |
Code | Description |
---|---|
200 | Returns the comment |
404 | The post or comment does not exist |
Delete comment by id
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
postId | path | post id | Yes | integer |
commentId | path | comment id | Yes | integer |
Code | Description |
---|---|
204 | Returns no content response |
404 | Post or comment does not exist |
Update comment for post by id
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
postId | path | Post id | Yes | integer |
commentId | path | Comment id | Yes | integer |
Code | Description |
---|---|
204 | Returns no content response |
400 | Comment input object is null |
404 | Post or comment does not exist |
422 | Invalid model state for comment input object |
Partially update comment for post by id
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
postId | path | Post id | Yes | integer |
commentId | path | Comment id | Yes | integer |
Code | Description |
---|---|
204 | Returns no content response |
400 | Comment input object sent from client is null |
404 | Post or comment does not exist |
422 | Invalid model state for the comment input object |
Get a list of comments by ids
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
ids | query | A comma-separated string of integers | Yes | [ integer ] |
postId | path | Yes | string |
Code | Description |
---|---|
200 | Returns a list of comments |
400 | Parameter ids is null |
404 | Some ids are not valid in a collection |
Get a list of posts for category
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
categoryId | path | Category id | Yes | integer |
Code | Description |
---|---|
200 | Returns a list of posts |
404 | Category does not exist |
Create a post for category
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
categoryId | path | Category id | Yes | integer |
Code | Description |
---|---|
201 | Returns the newly created post |
400 | Post input object is null |
404 | Category does not exist |
422 | Invalid model state for post input object |
Get a list of all posts regardless of category
Code | Description |
---|---|
200 | Returns a list of posts |
Get a post by id
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
postId | path | post id | Yes | integer |
Code | Description |
---|---|
200 | Returns a posts |
404 | Post does not exist |
Delete a post by id
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
postId | path | Post id | Yes | integer |
Code | Description |
---|---|
204 | Returns no content response |
404 | Post does not exist |
Update a post by id
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
postId | path | Post id | Yes | integer |
Code | Description |
---|---|
204 | Returns no content response |
400 | Post input object is null |
404 | Post does not exist |
422 | Invalid model state for post input object |
Partially update post by id
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
postId | path | Post id | Yes | integer |
Code | Description |
---|---|
204 | Returns no content response |
400 | Post input object sent from client is null |
404 | Post does not exist |
422 | Invalid model state for the post input object |
Get a list of posts by ids
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
ids | query | A comma-separated string of integers | Yes | [ integer ] |
Code | Description |
---|---|
200 | Returns a list of posts |
400 | Parameter ids is null |
404 | Some ids are not valid in a collection |
Create multiple posts for category
Name | Located in | Description | Required | Schema |
---|---|---|---|---|
categoryId | path | Category id | Yes | integer |
Code | Description |
---|---|
201 | Returns the newly created posts |
400 | Post input objects are null |
404 | Category does not exist |
422 | Invalid model state for post input object(s) |