| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Application
Description
This module contains the web application and API implementation of Breve.
Synopsis
- data ApiReply = ApiReply {}
- newtype UrlForm = UrlForm Text
- type Breve = API :<|> App
- type App = Get '[HTML] Html :<|> (("static" :> Raw) :<|> ((Capture "name" Name :> Redirect) :<|> (ReqBody '[FormUrlEncoded] UrlForm :> Post '[HTML] Html)))
- type API = "api" :> (ReqBody '[FormUrlEncoded] UrlForm :> Post '[JSON] ApiReply)
- breve :: FilePath -> Url -> UrlTable -> Application
- emptyApp :: Application
- breveServer :: FilePath -> Url -> UrlTable -> Server Breve
- homepage :: Handler Html
- resolver :: UrlTable -> Name -> Handler Redirection
- uploader :: Url -> UrlTable -> UrlForm -> Handler Html
- api :: Url -> UrlTable -> UrlForm -> Handler ApiReply
- logStr :: Text -> Handler ()
- type Redirect = Verb GET 302 '[PlainText] Redirection
- type Redirection = Headers '[Header "Location" Text] NoContent
Types
API successful reply
This is the reply returned by the JSON API handler when the url has been shortned successfully.
Constructors
| ApiReply | |
Instances
| Generic ApiReply Source # | |
| ToJSON ApiReply Source # | |
Defined in Application | |
| type Rep ApiReply Source # | |
Defined in Application type Rep ApiReply = D1 (MetaData "ApiReply" "Application" "main" False) (C1 (MetaCons "ApiReply" PrefixI True) (S1 (MetaSel (Just "link") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Url) :*: (S1 (MetaSel (Just "name") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Name) :*: S1 (MetaSel (Just "original") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 Url)))) | |
Breve API
type Breve = API :<|> App Source #
API spec
Breve has two main components:
- the web app
- 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 |
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.
uploader :: Url -> UrlTable -> UrlForm -> Handler Html Source #
Takes a UrlForm via POST
and prints the shortned one