Example - Tokyo’s zip-codes API
This is another example, based of an official list of zip codes in Tokyo.
It shows some parsing capabilities, and how to handle relationships between multiple inputs.
It takes a CSV file encoded as Shift_JIS
as an input, and provides an HTTP service with two endpoints.
The encoding is handled with a custom string parser that is assigned to the relevant columns.
Using a boolean parser, the strings 0
and 1
are converted to booleans.
Other CSV files containing some type definitions are loaded, and declared as relationships in the output, which means it gets inserted as a sub-object in the resulting JSON.
You can download and run this example locally (using Docker) with the following script.
The source code for this example is also available here.
List all the zip codes
This endpoint allows to list and filter the persons in the database:
GET http://localhost:3000/zip-codes
Response body:
List the zip codes of a specific municipality
This endpoint provides a municipality
parameter, that uses a map index.
GET http://localhost:3000/zip-codes?municipality=渋谷区
Response body:
Paging
The results are paged using customized offset_from
and max_per_page
parameters. The default value for max_per_page
is 30
.
Getting the second page with the default size:
GET http://localhost:3000/zip-codes?offset_from=30
Getting the third page with a size of 10 results per page
GET http://localhost:3000/zip-codes?max_per_page=10&offset_from=20
Get a specific zip-code’s information
This endpoint allows to get a specific record using it’s zip-code.
The zip-codes are also indexed using a map index.
GET http://localhost:3000/zip-codes/1350064
Response body: