rest-core-0.35.1: Rest API library.

Safe HaskellNone
LanguageHaskell98

Rest.Api

Contents

Description

This module allows you to combine Resources into an Api. This can then be served using 'rest-happstack' or 'rest-snap', or used to generate clients or documentation using 'rest-gen'.

Synopsis

Api data types.

type Api m = [(Version, Some1 (Router m))] Source

An API is a list of versioned routers.

data Router m s where Source

A Router is a Resource and a list of subresources.

Constructors

Embed :: Resource m s sid mid aid -> [Some1 (Router s)] -> Router m s 

data Some1 f where Source

An existential where the second argument has kind (* -> *).

Constructors

Some1 :: f (a :: * -> *) -> Some1 f 

Defining routes.

route :: Monad s => Resource m s sid mid aid -> Router m s Source

Convenience constructor constructing a route without any subresource.

compose :: Router m s -> Router s t -> Router m s Source

Add the second router as a subresource to the first.

(-/) :: Router m s -> Router s t -> Router m s infixl 4 Source

Operators with the right fixities to allow you to define routes without using parentheses. Start with the shortest near the root.

(--/) :: Router m s -> Router s t -> Router m s infixl 5 Source

Operators with the right fixities to allow you to define routes without using parentheses. Start with the shortest near the root.

(---/) :: Router m s -> Router s t -> Router m s infixl 6 Source

Operators with the right fixities to allow you to define routes without using parentheses. Start with the shortest near the root.

(----/) :: Router m s -> Router s t -> Router m s infixl 7 Source

Operators with the right fixities to allow you to define routes without using parentheses. Start with the shortest near the root.

(-----/) :: Router m s -> Router s t -> Router m s infixl 8 Source

Operators with the right fixities to allow you to define routes without using parentheses. Start with the shortest near the root.

(------/) :: Router m s -> Router s t -> Router m s infixl 9 Source

Operators with the right fixities to allow you to define routes without using parentheses. Start with the shortest near the root.

root :: (Applicative m, Monad m) => Router m m Source

An empty router to use as the root for your API.

Api versioning.

data Version Source

An API version has three parts. The first is two are used for API breaking changes, the last for non-API breaking changes.

Constructors

Version 

Fields

full :: Int
 
major :: Int
 
minor :: Maybe Int
 

mkVersion :: Int -> Int -> Int -> Version Source

Smart constructor for Version.

latest :: Api m -> Maybe (Version, Some1 (Router m)) Source

Get the latest version of an API.

parseVersion :: String -> Maybe Version Source

Parse a String as a Version. The string should contain two or three numbers separated by dots, e.g. 1.12.3.

lookupVersion :: String -> Api m -> Maybe (Some1 (Router m)) Source

Look up a version in an API. The string can either be a valid version according to parseVersion, or "latest".

lookupVersion' :: Version -> Api m -> Maybe (Some1 (Router m)) Source

Look up a version in the API.

withVersion :: String -> Api m -> r -> (Version -> Some1 (Router m) -> r) -> r Source

Given a version string, an API and a fallback, do the following:

  • Parse the version number or "latest".
  • Look up this version.
  • If ok, run the given function on it.
  • If not parsed or found, return the fallback.