# 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.

[1]:

%load_ext raw_magic


If we define a view such as:

[3]:

%%view view_as_webservice

SELECT * FROM ["Hello", "World"]


This view can be queried in the endpoint:

https://<SERVER ADDRESS>/query-view/view_as_webservice


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.: X-RAW-output-format: json.

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:

[14]:

%%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_by_country and airports_in_city.

For instance, airports_in_city can be queried in the endpoint:

https://<SERVER ADDRESS>/query-package/package_as_webservice/airports_in_city?city=Lisbon