We are going to add REST API interface to our forum, and we decided to begin with creating endpoints without authentication. It won't be secure but it will make development process easier. We will add authentication to these endpoints in the future.
We need an endpoint which will return the list of posts from particular topic with abitily to sort results. Sorting will be specified via order_by query parameter. order_by should accept a string with two words separated by comma. First word is the name of the sorting field (only created_at is acceptable for now). Second word is the sorting direction (asc or desc). If there were no order_by provided, then return posts ordered by created_at ascending.
So in the scope of this task we need to create an endpoint GET /api/topics/42/posts which will return list of posts info in json format, or 400 if request is not valid, or 404 if topic doesn't exist.
We are going to add REST API interface to our forum, and we decided to begin with creating endpoints without authentication. It won't be secure but it will make development process easier. We will add authentication to these endpoints in the future.
We need an endpoint which will return the list of posts from particular topic with abitily to sort results. Sorting will be specified via
order_by
query parameter.order_by
should accept a string with two words separated by comma. First word is the name of the sorting field (onlycreated_at
is acceptable for now). Second word is the sorting direction (asc
ordesc
). If there were noorder_by
provided, then return posts ordered bycreated_at
ascending.Request example:
Response example:
So in the scope of this task we need to create an endpoint
GET /api/topics/42/posts
which will return list of posts info in json format, or 400 if request is not valid, or 404 if topic doesn't exist.