This repository is an API that fetches data from another API (Hatchways)
You can use this repository's API through the following URL :
https://dibe-api-hatchways.herokuapp.com
- Clone this repository to your local machine
- Make sure
NodeJS
is installed in your machine - Install the packages:
npm install
- Run the project:
npm start
IMPORTANT:
Once you run the server, it will generate a file called "output.txt"
where you can check some outputs examples when callling the routes.
If you do not want the file to be generated, please comment out the
function call generateOutputs()
in server.js
- Open two terminals
- In one terminal start the server:
npm start
- In the other terminal run the test:
npm test
- Route: /api/ping
- Method: GET
- Route: /api/posts
- Method: GET
- Query Parameters:
Field | Type | Description | Default | Example |
---|---|---|---|---|
tags | String (required) | A comma separated list of tags. | N/A | science,tech |
sortBy | String (optional) | The field to sort the posts by. Acceptable fields are: ● id ● reads ● likes ● popularity |
id | popularity |
direction | String (optional) | The direction for sorting. The acceptable fields are: ● desc ● asc |
asc | asc |
- The API response will be a list of all the blog posts that have at least one tag
specified in the tags parameter.
- The sortBy parameter specifies which field should be used to sort the returned
results.
- The direction parameter specifies if the results should be returned in ascending
order (if the value is "asc") or descending order (if the value is "desc")
ERROR Responses Example:
- If tags
parameter is not present:
- If a sortBy
or direction
are invalid values, specify an error like below:
The Hatchway API is the one used in this repository to fetch data from. The data fetched is filtered and sorted according to the query parameters specified before. This API only accepts one query parameter, diferently from the API developed in this repository, that accepts 3 query parameters.
- Route: https://api.hatchways.io/assessment/blog/posts
- Method: GET
- Query Parameters:
Field | Type | Description |
---|---|---|
tag | String (required) | The tag associated with the blog post. |
- Example:
https://api.hatchways.io/assessment/blog/posts?tag=tech
The url above would result the following: