|
| 1 | +--- |
| 2 | +date: 2023-08-30 |
| 3 | +authors: |
| 4 | + name: Jimmy Yeh |
| 5 | + title: core member of VulcanSQL |
| 6 | + url: https://github.com/cyyeh |
| 7 | + image_url: https://avatars.githubusercontent.com/u/11023068?v=4 |
| 8 | + email: jimmy.yeh@cannerdata.com |
| 9 | +--- |
| 10 | + |
| 11 | +# Query Data from the Internet and Deliver APIs in no time |
| 12 | + |
| 13 | +*TLDR: VulcanSQL, a free and open-source data API framework built specifically for data applications, |
| 14 | +empowers data professionals to generate and distribute data APIs quickly and effortlessly. |
| 15 | +It takes your SQL templates and transforms them into data APIs, with no backend expertise necessary.* |
| 16 | + |
| 17 | +## One Way to Understand APIs |
| 18 | + |
| 19 | +As an API designer, we can think of APIs composed of three components, namely **input**, **transformation** and **output**. |
| 20 | + |
| 21 | +Let's start with the input component, we need to consider what are data sources of APIs. Generally, data sources |
| 22 | +can be databases, files on the FTP server, etc. After we decide what data sources our APIs support, we need to |
| 23 | +also support different mechanisms in order to get data from data sources. |
| 24 | + |
| 25 | +Then, with the transformation part, it generally is where we handle business logic. Finally, the output part means the destination |
| 26 | +of the APIs and also the mechanisms we deliver the APIs, such as RESTful APIs, GraphQL, etc. |
| 27 | + |
| 28 | +Now, let me take VulcanSQL as a quick example, it emphasizes you can write SQL templates in the transformation part, |
| 29 | +and it currently supports RESTful APIs for the output part. As of the input, please read the following content to grasp the full story! |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +<!--truncate--> |
| 34 | + |
| 35 | +## The Input Part: Data Sources |
| 36 | + |
| 37 | +VulcanSQL aims to help data professionals create and deliver data APIs in an easy way! |
| 38 | +Originally, VulcanSQL supports data warehouses and some databases such as [BigQuery](../docs/connectors/bigquery), |
| 39 | +[Snowflake](../docs/connectors/snowflake), [ClickHouse](../docs/connectors/clickhouse) and [PostgreSQL](../docs/connectors/postgresql), etc. However, as we share VulcanSQL to the world |
| 40 | +along the way, we figured out that there are also lots of data on the Internet that is not in databases |
| 41 | +such as CSV files or data that lives in other people's databases! |
| 42 | + |
| 43 | +That's what we're going to share with you next: how VulcanSQL can help you get data from the Internet! |
| 44 | + |
| 45 | +## How VulcanSQL can help? |
| 46 | + |
| 47 | +As of now, VulcanSQL provides two mechanisms to help you get data from the Internet. |
| 48 | + |
| 49 | +### DuckDB and its httpfs extension |
| 50 | + |
| 51 | +In VulcanSQL, we can use [DuckDB](../docs/connectors/duckdb) as a caching layer to [enhance query performance](./powering-rapid-data-apps-with-vulcansql), or as a data connector. |
| 52 | +For those of you who may not be familiar with DuckDB, it is a high performance in-process OLAP database, |
| 53 | +and has lots of extensions available! In order to get data from the Internet, VulcanSQL supports the httpfs extension! |
| 54 | + |
| 55 | +With the [httpfs extension](https://duckdb.org/docs/extensions/httpfs.html), now VulcanSQL can query CSV, JSON and Parquet files from the Internet! |
| 56 | + |
| 57 | +Imagine now you find some interesting dataset on the Internet, and it's a CSV file! Now you can directly query it |
| 58 | +like the following SQL statement, then you can do some data transformation using SQL, and deliver APIs right away to share with others! |
| 59 | + |
| 60 | +```sql |
| 61 | +SELECT |
| 62 | + * |
| 63 | +FROM 'https://www.stats.govt.nz/assets/Uploads/Annual-enterprise-survey/Annual-enterprise-survey-2021-financial-year-provisional/Download-data/annual-enterprise-survey-2021-financial-year-provisional-csv.csv' |
| 64 | +``` |
| 65 | + |
| 66 | +The image below shows the data details using VulcanSQL's [API Catalog feature](../docs/catalog/intro) |
| 67 | + |
| 68 | + |
| 69 | +If you would like to read the source code of the full example, please [check out here](https://github.com/Canner/vulcan-sql-examples/tree/main/read-data-from-internet)! |
| 70 | + |
| 71 | +### The API Extension |
| 72 | + |
| 73 | +Sometimes, you may find some interesting data from RESTful APIs created by others. VulcanSQL now has [the API extension](../docs/extensions/api) that |
| 74 | +allows you to query data from 3rd parties using RESTful APIs! |
| 75 | + |
| 76 | +In the following example, we call the RESTful API to `https://dummyjson.com` and search their products with a query string! |
| 77 | + |
| 78 | +```sql |
| 79 | +{% set a_variable_you_can_define = { "query": { "q": "phone" } } %} |
| 80 | +SELECT {{ a_variable_you_can_define | rest_api(url='https://dummyjson.com/products/search') }} |
| 81 | +``` |
| 82 | + |
| 83 | +Besides, the API Extension not only supports the GET method, but also other HTTP methods as well! |
| 84 | + |
| 85 | +If you would like to read the source code of the full example, please [check out here](https://github.com/Canner/vulcan-sql-examples/tree/main/restapi-caller). |
| 86 | + |
| 87 | +## Conclusion |
| 88 | + |
| 89 | +We hope this blog post demonstrates how VulcanSQL can help you query data from the Internet, thus you can create and deliver APIs in no time! |
0 commit comments