Create a GET /api/v3/titanic/passengers
API endpoint using the HTTP In node. The call must support the following query parameters:
survived
ticket_class
sex
age
embarked
sort
- sort the results based on a parameter. This query parameter can accept the following values:
age
- sort the results by age
name
- sort the results by name
fare
- sort the results by fare
sort_order
- the order for the sorting. This query parameter should accept the following values:
asc
- ascending order (smallest to largest), e.g. 0 → 9, A → Z
desc
- descending order (largest to smallest), e.g. 9 → 0, Z → A
page
(needed for the pagination)
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
The API endpoint should check if the key is matching and only then proceed with the rest of the operation
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:
PassengerId
-> id
Survived
→ survived
Pclass
-> ticketClass
Name
→ name
Sex
→ sex
Age
→ age
SibSp
→ siblingsSpouses
Parch
→ parentsChildren
Ticket
→ ticketNumber
Fare
→ fare
Cabin
→ cabinNumber
Embarked
→ embarked
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:
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"
},
...
]
}