Learn how to create an API to your data with the Latitude framework
views
directory from your project.
sources
directory.
For this guide, we’ll use the CSV that comes with the sample project, but you can replace that with any other CSV or connect to a live database following these instructions.
Go ahead and download the sample CSV and save it in the queries
directory as source.csv
.
Cmd + S
or Ctrl + S
to save the filesample.sql
in the queries
directory and write the following query:
source.csv
file using our default DuckDB adapter (you don’t need to configure anything else to get this working).
Next, let’s create a secondary query to aggregate some data. Create a new file named sample_agg.sql
in the queries
directory and write the following query:
ref
function is used to interpolate the sample.sql
query, and use its results as the input for this query. Latitude allows you to chain queries together very easily, find out more about this in the queries reference.
To check that your queries are working as expected, you can run them locally using the latitude run
command. For example:
/queries/sample_agg.sql
query once and display the results in your terminal.
Learn more about latitude run
in the CLI reference.
curl
, Postman, or even your browser. For example, to access the /api/queries/sample_agg
endpoint, you can run the following command in your terminal:
sample_agg.sql
query in JSON format.
sample_agg.sql
file to support a year
parameter. Replace the contents of the file with the following and save it:
year
parameter to the /api/queries/sample_agg
endpoint. For example, to get the results for the year 2020, you can run the following command in your terminal:
sample_agg.sql
query for the year 2020 in JSON format.
__download
boolean parameter to the URL to download
the results as a CSV file. For example, to download the results of the
sample_agg.sql
query as a CSV file, you can run the following command in your
terminal: