breve

Safe HaskellNone
LanguageHaskell2010

Application

Contents

Description

This module contains the web application and API implementation of Breve.

Synopsis

Types

data ApiReply Source #

API successful reply

This is the reply returned by the JSON API handler when the url has been shortned successfully.

Constructors

ApiReply 

Fields

Instances
Generic ApiReply Source # 
Instance details

Defined in Application

Associated Types

type Rep ApiReply :: Type -> Type #

Methods

from :: ApiReply -> Rep ApiReply x #

to :: Rep ApiReply x -> ApiReply #

ToJSON ApiReply Source # 
Instance details

Defined in Application

type Rep ApiReply Source # 
Instance details

Defined in Application

newtype UrlForm Source #

This type is just a wrapper around a Text value. It's used to create a FromForm instance for a Url.

Constructors

UrlForm Text 
Instances
FromForm UrlForm Source # 
Instance details

Defined in Application

Breve API

type Breve = API :<|> App Source #

API spec

Breve has two main components:

  1. the web app
  2. the JSON API itself

type App = Get '[HTML] Html :<|> (("static" :> Raw) :<|> ((Capture "name" Name :> Redirect) :<|> (ReqBody '[FormUrlEncoded] UrlForm :> Post '[HTML] Html))) Source #

Web app spec

path type description
/ GET homepage
/ POST upload a new url
/static GET static assets
/:name GET resolves a short url

type API = "api" :> (ReqBody '[FormUrlEncoded] UrlForm :> Post '[JSON] ApiReply) Source #

JSON API spec

path type description
/api POST upload a new url

breve Source #

Arguments

:: FilePath

static assets path

-> Url

bind url

-> UrlTable

url hashtable

-> Application 

Breve application

emptyApp :: Application Source #

Empty application

This app does *nothing* but it's useful nonetheless: it will be used as a basis to run the forceSSL middleware.

Handlers

breveServer :: FilePath -> Url -> UrlTable -> Server Breve Source #

Breve server

This is just an ordered collection of handlers following the Breve API spec.

homepage :: Handler Html Source #

Serves the homepage

resolver :: UrlTable -> Name -> Handler Redirection Source #

Resolves a Name to the full Url

uploader :: Url -> UrlTable -> UrlForm -> Handler Html Source #

Takes a UrlForm via POST and prints the shortned one

api :: Url -> UrlTable -> UrlForm -> Handler ApiReply Source #

Takes a Url via POST and returns the shortned one in an ApiReply as JSON.

Misc

logStr :: Text -> Handler () Source #

Handy function to log to stdout

type Redirect = Verb GET 302 '[PlainText] Redirection Source #

Verb that encodes an HTTP 302 redirection

type Redirection = Headers '[Header "Location" Text] NoContent Source #

Reply with Location redirect header