17. Creating Web Services¶
RAW entities - views, materialized views, packages and tables - are available as REST services.
This means that to create a “Web Service” in RAW, all you need to do is, for instance, define a view.
If we define a view such as:
%%view view_as_webservice SELECT * FROM ["Hello", "World"]
This view can be queried in the endpoint:
The HTTP request needs the uthorization token to be passed in the header:
Authorization: Bearer <TOKEN>.
In addition, to obtain output in a specific format, the optional header
X-RAW-output-format can be passed, e.g.:
In the case of packages, parameters can also be passed. That’s because packages can contain function declarations that take parameters.
Let’s assume a package is defined as:
%%package package_as_webservice private airports := SELECT * FROM READ("https://raw-tutorial.s3.amazonaws.com/airports.csv"); airports_by_country := SELECT Country, * FROM airports GROUP BY Country; airports_in_city(city: string) := SELECT * FROM airports WHERE City = city;
This package exposes two web services, corresponding to the methods
airports_in_city can be queried in the endpoint: