Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Bimap.Server
Description
A bimap server is basically a server that stores a one-to-one correspondence between two sets of values. You can think of it as a table with two columns, where each column has elements of the same type. You can lookup the table and update it using JSON based HTTP requests.
This is how you run the server:
bimapServer (Proxy :: Proxy Int) -- This proxy specifies the type of the values in the left column (Proxy :: Proxy String) -- This proxy specifies the type of the values in the right column 5000 -- Server will be running in port 5000 60 -- This is the number of seconds between saves
In this example, the server will save in the file "saved.bimap"
the table every 60 seconds.
Keep in mind that bimapServer
will install a handle for SIGTERM signals, meaning that a kill
signal
will be catched by the process, triggering a save of the table. After saving the table, the server will
stop running. However, the port that the server was using may still not be available until the program
using bimapServer
is closed.
The interface of the server is as follows:
- [GET]
/list
: Returns the list of rows in the table. The format is[[a1,b1],...,[aN,bN]]
. You can use the aeson's encoding of the type[(a,b)]
for decoding it. - [GET]
/left-lookup
: Lookup an element in the table by searching in the left column. It returns the element in the right column (if any) in JSON format as described by theToJSON
instance. The element to lookup is specified using its JSON encoded form as the body of the HTTP request. - [GET]
/right-lookup
: Just as/left-lookup
, except that using the right column for searching, and returning the element in the left column (if any). - [POST]
/insert
: Insert a pair of values in the table, replacing any occurences. The pair is sent in the body of the HTTP request, in JSON format, using the aeson's encoding of pairs (tuples of size 2). - [DELETE]
/left-delete
: Delete a row by searching in the left column. The value to look for in the left column is passed JSON-encoded as the body of the HTTP request. - [DELETE]
/right-delete
: Just as/left-delete
, but searching in the right column.