Skip to content

ArthurDibe/NodeAPI_Hatchways

Repository files navigation

Dibe's API - Hatchways

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

How to locally Run this project:

  1. Clone this repository to your local machine
  2. Make sure NodeJS is installed in your machine
  3. Install the packages: npm install
  4. 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

How to locally Run Tests:

  1. Open two terminals
  2. In one terminal start the server: npm start
  3. In the other terminal run the test: npm test




About the routes

- Route 1

  • Route:    /api/ping
  • Method: GET


- Route 2

  • 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 Responses:

- 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")

SUCCESS Response Example:


ERROR Responses Example:

- If tags parameter is not present:


- If a sortBy or direction are invalid values, specify an error like below:




About the Hatchways's API:

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.


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:
      



About

This repository is about an API that fetches data from another API (Hatchways)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published