-
Notifications
You must be signed in to change notification settings - Fork 1
Defining services
Once you have installed Slumber you can start defining services.
The default HTTP handler uses implicit configuration which means that Slumber will look through the assemblies in your web application's bin folder for a type which implements the Slumber.Framework.Core.IContainerDescription interface. This interface has a single member, Describe, which defines a group of services, or container, relative to the application's base URL.
The code below shows a simple configuration that exposes two functions as REST services.
namespace MyApp
open System
open Slumber
open Slumber.Framework
open Slumber.Setup
open Slumber.IO.DataContract
type Config () =
interface IContainerDescription with
member this.Describe baseUrl =
containerAt (relativeUrl baseUrl "/api")
|> with' (
endpointAt "/people"
|> named "people"
|> supporting (get People.getPeople)
|> supporting (post People.createPerson)
)
|> reading MediaTypes.Text.Xml Xml.read
|> writing MediaTypes.Text.Xml Xml.writeThis configuration specifies that the base URL for all services is the web application base URL plus /api - e.g. if the web application base URL is http://localhost/myapp then the services will be based at http://localhost/myapp/api.
The container has a single endpoint called "people" at /people. Endpoint URLs are relative to the container base URL, so using the previous example this endpoint would be at http://localhost/myapp/api/people.
The "people" endpoint has two bindings to HTTP verbs - one for GET and another for POST. These bindings expose the functions People.getPeople and People.createPerson respectively. The functions and arguments page describes how Slumber calls your functions.
Finally, the configuration specifies that the reading and writing of the text/xml content type is supported (i.e. as values for the Content-Type and Accept headers respectively) using the XML data contract serialisers found in Slumber.IO.DataContract.