Skip to main content
Skip table of contents

API Endpoint Design Assignment

Introduction

The following assignment would let you build a custom API endpoint that would retrieve TItanic CSV data from a URL convert it to JSON and visualize it on request. The API endpoint would be protected by a static API key passed as a header to your request.

Titanic Columns

Column Name

Description

Data Type

Example

PassengerId

ID of the passenger

integer

integer

Survived

Whether the passenger has survived or not

integer

0 = No, 1 = Yes

Pclass

Ticket class

integer

1 = 1st, 2 = 2nd, 3 = 3rd

Name

Name of the passenger

string

Moran, Mr. James

Sex

Sex of the passenger

string

female/male

Age

Age in years

integer

35

SibSp

Number of siblings / spouses aboard the Titanic

integer

2

Parch

Number of parents / children aboard the Titanic

integer

1

Ticket

Ticket number

string

A/5 21171

Fare

Passenger fare

float

51.8625

Cabin

Cabin number

string

C85

Embarked

Port of Embarkation

string

C = Cherbourg, Q = Queenstown, S = Southampton

Please note that not all records are complete and some are missing data for some of the columns.

Assignments

The assignment section is divided into two parts:

  1. Simple Assignments - These require relatively low effort.

  2. Advanced Assignments - These demand a higher level of effort for completion and are optional.

For each assignment, there is an Example Output section that provides an example of how the data should be formatted and returned to the API client requesting it.

Simple Assignments

GET /api/titanic/passengers (no query params)
  1. Create a GET /api/titanic/passengers API endpoint using the HTTP In node

  2. The call shall be protected by a static API key, passed to the headers as X-API-Key. Please use the following UUID (Universal Unique Identifier) 633aca31-b472-465a-a940-a018c0b34838 as a value to the X-API-Key

    1. The API endpoint should check if the key is matching and only then proceed with the rest of the data processing

    2. The API endpoint should return HTTP status code 401 (Unauthorized) in case the provided API key is invalid or missing.

  3. Retrieve the data from https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv. Please note that the provided data is in CSV (comma-separated values) format and you would need to convert it to a JSON format for easier processing.

You can use the CSV parser node

  1. Rename and conver the column names into camel case:

    1. PassengerId -> id

    2. Survivedsurvived

    3. Pclass -> ticketClass

    4. Namename

    5. Sexsex

    6. Ageage

    7. SibSpsiblingsSpouses

    8. ParchparentsChildren

    9. TicketticketNumber

    10. Farefare

    11. CabincabinNumber

    12. Embarkedembarked

  2. Convert the values under the survived column to a boolean value (0 → false and 1 -> true)

  3. Convert the values under the embarked column to the full name of the port of embarkation (C → Cherbourg, Q → Queenstown, S → Southampton)

  4. Create API documentation describing the possible response codes and add a description and a tag of the API endpoint

Example Output:

GET /api/titanic/passengers:

JSON
[
{
   "id": 1,
   "survived": false,
   "ticketClass": 3,
   "name": "Braund, Mr. Owen Harris",
   "sex": "male",
   "age": 22,
   "siblingsSpouses": 1,
   "parentsChildren": 0,
   "ticketNumber": "A/5 21171",
   "fare": 7.25,
   "embarked": "Southampton"
},
{
   "id": 2,
   "survived": true,
   "ticketClass": 1,
   "name": "Cumings, Mrs. John Bradley (Florence Briggs Thayer)",
   "sex": "female",
   "age": 38,
   "siblingsSpouses": 1,
   "parentsChildren": 0,
   "ticketNumber": "PC 17599",
   "fare": 71.2833,
   "cabin": "C85"
   "embarked": "Southampton"
}
...
]
GET /api/titanic/passengers/:id (path param)
  1. Create a GET /api/titanic/passengers/:id API endpoint using the HTTP In node, where :id is a path parameter. Upon providing a valid ID of the passenger, the API endpoint should return only the data for that particular passenger.

  2. The call shall be protected by a static API key, passed to the headers as X-API-Key. Please use the following UUID (Universal Unique Identifier) 633aca31-b472-465a-a940-a018c0b34838 as a value to the X-API-Key

    1. The API endpoint should check if the key is matching and only then proceed with the rest of the operation

    2. The API endpoint should return HTTP status code 401 (Unauthorized) in case the provided API key is invalid or missing.

  3. Retrieve the data from https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv. Please note that the provided data is in CSV (comma-separated values) format and you would need to convert it to a JSON format for easier processing.

You can use the CSV parser node

  1. Rename and conver the column names into camel case:

    1. PassengerId -> id

    2. Survivedsurvived

    3. Pclass -> ticketClass

    4. Namename

    5. Sexsex

    6. Ageage

    7. SibSpsiblingsSpouses

    8. ParchparentsChildren

    9. TicketticketNumber

    10. Farefare

    11. CabincabinNumber

    12. Embarkedembarked

  2. Convert the values under the survived column to a Boolean value (0 → false and 1 -> true)

  3. Convert the values under the embarked column to the full name of the port of embarkation (C → Cherbourg, Q → Queenstown, S → Southampton)

  4. The call shall return HTTP status code 404 in case the provided passenger ID is not found.

  5. Create API documentation describing the possible response codes and add a description and a tag of the API endpoint

Example Output:

GET /api/titanic/passengers/1

JSON
{
   "id": 1,
   "survived": false,
   "ticketClass": 3,
   "name": "Braund, Mr. Owen Harris",
   "sex": "male",
   "age": 22,
   "siblingsSpouses": 1,
   "parentsChildren": 0,
   "ticketNumber": "A/5 21171",
   "fare": 7.25,
   "embarked": "Southampton"
}

Advanced Assignments

GET /api/titanic/passengers (introducing queries)
  1. Create a GET /api/v2/titanic/passengers API endpoint using the HTTP In node. The call must support the following query parameters:

    1. survived

    2. ticket_class

    3. sex

    4. age

    5. embarked

  2. The call shall be protected by a static API key, passed to the headers as X-API-Key. Please use the following UUID (Universal Unique Identifier) 633aca31-b472-465a-a940-a018c0b34838 as a value to the X-API-Key

    1. The API endpoint should check if the key is matching and only then proceed with the rest of the operation

    2. The API endpoint should return HTTP status code 401 (Unauthorized) in case the provided API key is invalid or missing.

  3. Retrieve the data from https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv. Please note that the provided data is in CSV (comma-separated values) format and you would need to convert it to a JSON format for easier processing.

You can use the CSV parser node

  1. Rename and conver the column names into camel case:

    1. PassengerId -> id

    2. Survivedsurvived

    3. Pclass -> ticketClass

    4. Namename

    5. Sexsex

    6. Ageage

    7. SibSpsiblingsSpouses

    8. ParchparentsChildren

    9. TicketticketNumber

    10. Farefare

    11. CabincabinNumber

    12. Embarkedembarked

  2. Convert the values under the survived column to a Boolean value (0 → false and 1 -> true)

  3. Convert the values under the embarked column to the full name of the port of embarkation (C → Cherbourg, Q → Queenstown, S → Southampton)

  4. Create API documentation describing the possible response codes and add a description and a tag of the API endpoint

  5. The call should only return results if all the query conditions provided in the GET call are met.

  6. The query parameters in the URL should be case insensitive, meaning that providing the query as Survived, SURVIVED and survived should all return the same result.

  7. The resulting JSON should also return the number of matches by introducing a new parameter called count: {numberOfMatches}.

    Example Output:

GET /api/v2/titanic/passengers?survived=false&sex=male&age=30

The below provided JSON file should be corrected with an actual count and the first two matching entries!

JSON
{
   "count":13,
   "data":[
      {
         "id":158,
         "survived":false,
         "ticketClass":3,
         "name":"Corn, Mr. Harry",
         "sex":"male",
         "age":30,
         "siblingsSpouses":0,
         "parentsChildren":0,
         "ticketNumber":"SOTON/OQ 392090",
         "fare":8.05,
         "embarked":"Southampton"
      },
      {
         "id":179,
         "survived":false,
         "ticketClass":2,
         "name":"Hale, Mr. Reginald",
         "sex":"male",
         "age":30,
         "siblingsSpouses":0,
         "parentsChildren":0,
         "ticketNumber":"250653",
         "fare":13,
         "embarked":"Southampton"
      },
      ...
  ]
}
GET /api/titanic/passengers (introducing queries and pagination)
  • Create a GET /api/v3/titanic/passengers API endpoint using the HTTP In node. The call must support the following query parameters:

    1. survived

    2. ticket_class

    3. sex

    4. age

    5. embarked

    6. sort - sort the results based on a parameter. This query parameter can accept the following values:

      1. age - sort the results by age

      2. name - sort the results by name

      3. fare - sort the results by fare

    7. sort_order - the order for the sorting. This query parameter should accept the following values:

      1. asc - ascending order (smallest to largest), e.g. 0 → 9, A → Z

      2. desc - descending order (largest to smallest), e.g. 9 → 0, Z → A

    8. page (needed for the pagination)

    9. per_page (needed for the pagination)

  • The call shall be protected by a static API key, passed to the headers as X-API-Key. Please use the following UUID (Universal Unique Identifier) 633aca31-b472-465a-a940-a018c0b34838 as a value to the X-API-Key

    1. The API endpoint should check if the key is matching and only then proceed with the rest of the operation

    2. The API endpoint should return HTTP status code 401 (Unauthorized) in case the provided API key is invalid or missing.

  • Retrieve the data from https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv. Please note that the provided data is in CSV (comma-separated values) format and you would need to convert it to a JSON format for easier processing.

  • Rename and conver the column names into camel case:

    1. PassengerId -> id

    2. Survivedsurvived

    3. Pclass -> ticketClass

    4. Namename

    5. Sexsex

    6. Ageage

    7. SibSpsiblingsSpouses

    8. ParchparentsChildren

    9. TicketticketNumber

    10. Farefare

    11. CabincabinNumber

    12. Embarkedembarked

  • Convert the values under the survived column to a Boolean value (0 → false and 1 -> true)

  • Convert the values under the embarked column to the full name of the port of embarkation (C → Cherbourg, Q → Queenstown, S → Southampton)

  • Create API documentation describing the possible response codes and add a description and a tag of the API endpoint

  • The call should only return results if all the query conditions provided in the GET call are met.

  • The query parameters in the URL should be case insensitive, meaning that providing the query as Survived, SURVIVED and survived should all return the same result.

  • The pagination should introduce two new query parameters:

    • page - the number of the page

    • per_page - how many results per page should be returned. The maximum value of the per_page parameter should be limited to 100.

  • The resulting JSON should also return the number of matches by introducing a couple of new parameters:

    • count - the number of matches on the current page

    • total - total number of matches across all the pages

    • firstPage - the URL of the first page

    • previousPage - the URL of the previous page

    • currentPage - the URL of the current page

    • nextPage - the URL of the following page

    • lastPage - the URL of the last page

Example Output:

GET /api/titanic/v3/passengers?survived=false&page=4&per_page=50

In the example payload below, the nextPage value is null as the requested page is the final page, hence the fact that both currentPage and lastPage share the same value.

JSON
{
   "count":50,
   "total":549,
   "firstPage":"/api/v3/titanic/passengers?page=1&per_page=50",
   "previousPage":"/api/v3/titanic/passengers?page=3&per_page=50"
   "currentPage":"/api/v3/titanic/passengers?page=4&per_page=50",
   "nextPage":"/api/v3/titanic/passengers?page=5&per_page=50",
   "lastPage":"/api/v3/titanic/passengers?page=11&per_page=50",
   "data":[
      {
         "id":737,
         "survived":false,
         "ticketClass":3,
         "name":"Ford, Mrs. Edward (Margaret Ann Watson)",
         "sex":"female",
         "age":48,
         "siblingsSpouses":1,
         "parentsChildren":3,
         "ticketNumber":"W./C. 6608",
         "fare":34.375,
         "embarked":"Southampton"
      },
      {
         "id":453,
         "survived":false,
         "ticketClass":1,
         "name":"Foreman, Mr. Benjamin Laventall",
         "sex":"male",
         "age":30,
         "siblingsSpouses":0,
         "parentsChildren":0,
         "ticketNumber":"113051",
         "fare":27.75,
         "cabinNumber":"C111",
         "embarked":"Cherbourg"
      },
      ...
  ]
}

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.