%feature by ~hanfel-dovned hosts a simple HTML page from an Urbit ship at an associated URL. This tutorial examines how it uses the middleware %schooner library by Quartus to return a web page when contacted by a web browser. You will learn how a basic site hosting app can handle HTTP requests and render a page using an %html mark.
%feature presents a web page from /app/feature-ui at /apps/feature/feature-ui. These paths are both configurable by the developer.
/sur Structure Files
Our primary event in this case is simply an %action to create a page.
/sur/feature.hoon:
|%
+$ action
$% [%new-page html=@t]
==
--
No special mark files are necessary for %feature other than %html.
/app Agent Files
The agent only maintains a state containing the page contents as a cord.
The system only handles pokes: there are no subscriptions or Arvo calls except for the Eyre binding.
This arm uses the server library and schooner to produce a response of a server state and associated data. HTTP requests to /apps/feature are checked for login authentication, while /apps/feature/public are not.
POST
In response to a POST request, the default page in the state can be changed. This is the only state change supported by the agent.
GET
A GET request defaults to a 404 error.
/apps/feature/public returns 200 success and the default page in the state.
/apps/feature returns 200 success and the target page, statically compiled on agent build.
/lib/schooner
The Schooner library simplifies raw HTTP handling for Gall agents, in particular for MIME returns.