postgrest-0.3.0.2: REST API for any Postgres database

Safe HaskellNone
LanguageHaskell2010

PostgREST.ApiRequest

Synopsis

Documentation

data Action Source

Types of things a user wants to do to tablesviewsprocs

Instances

data Target Source

The target db object of a user action

data PreferRepresentation Source

How to return the inserted data

Constructors

Full 
HeadersOnly 
None 

data ContentType Source

Enumeration of currently supported content types for route responses and upload payloads

Constructors

ApplicationJSON 
TextCSV 

data ApiRequest Source

Describes what the user wants to do. This data type is a translation of the raw elements of an HTTP request into domain specific language. There is no guarantee that the intent is sensible, it is up to a later stage of processing to determine if it is an action we are able to perform.

Constructors

ApiRequest 

Fields

iAction :: Action

Set to Nothing for unknown HTTP verbs

iRange :: NonnegRange

Set to Nothing for malformed range

iTarget :: Target

Set to Nothing for strangely nested urls

iAccepts :: Either ByteString ContentType

The content type the client most desires (or JSON if undecided)

iPayload :: Maybe Payload

Data sent by client and used for mutation actions

iPreferRepresentation :: PreferRepresentation

If client wants created items echoed back

iPreferSingular :: Bool

If client wants first row as raw object

iPreferCount :: Bool

Whether the client wants a result count (slower)

iFilters :: [(String, String)]

Filters on the result ("id", "eq.10")

iSelect :: String

&select parameter used to shape the response

iOrder :: Maybe String

&order parameter

userApiRequest :: Schema -> Request -> RequestBody -> ApiRequest Source

Examines HTTP request and translates it into user intent.

pickContentType :: Maybe ByteString -> Either ByteString ContentType Source

Picks a preferred content type from an Accept header (or from Content-Type as a degenerate case).

For example text/csv -> TextCSV */* -> ApplicationJSON textcsv, applicationjson -> TextCSV applicationjson, textcsv -> ApplicationJSON

csvToJson :: (Header, CsvData) -> Array Source

Converts CSV like a,b 1,hi 2,bye

into a JSON array like [ {"a": "1", "b": "hi"}, {"a": 2, "b": "bye"} ]

The reason for its odd signature is so that it can compose directly with CSV.decodeByName

pluralize :: Value -> Array Source

Convert {foo} to [{foo}], leave arrays unchanged and truncate everything else to an empty array.

ensureUniform :: Array -> Maybe UniformObjects Source

Test that Array contains only Objects having the same keys and if so mark it as UniformObjects