Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module serves the purpose of defining common functionality which remains the same across all OpenAPI specifications.
Synopsis
- data Configuration s = Configuration {}
- doCallWithConfiguration :: (MonadHTTP m, SecurityScheme s) => Configuration s -> Text -> Text -> [(Text, Maybe String)] -> m (Either HttpException (Response ByteString))
- doCallWithConfigurationM :: (MonadHTTP m, SecurityScheme s) => Text -> Text -> [(Text, Maybe String)] -> ReaderT (Configuration s) m (Either HttpException (Response ByteString))
- doBodyCallWithConfiguration :: (MonadHTTP m, SecurityScheme s, ToJSON body) => Configuration s -> Text -> Text -> [(Text, Maybe String)] -> body -> RequestBodyEncoding -> m (Either HttpException (Response ByteString))
- doBodyCallWithConfigurationM :: (MonadHTTP m, SecurityScheme s, ToJSON body) => Text -> Text -> [(Text, Maybe String)] -> body -> RequestBodyEncoding -> ReaderT (Configuration s) m (Either HttpException (Response ByteString))
- runWithConfiguration :: SecurityScheme s => Configuration s -> ReaderT (Configuration s) m a -> m a
- class Monad m => MonadHTTP m where
- httpBS :: Request -> m (Either HttpException (Response ByteString))
- stringifyModel :: StringifyModel a => a -> String
- class Show a => StringifyModel a
- class SecurityScheme s where
- authenticateRequest :: s -> Request -> Request
- data AnonymousSecurityScheme = AnonymousSecurityScheme
- textToByte :: Text -> ByteString
- newtype JsonByteString = JsonByteString ByteString
- newtype JsonDateTime = JsonDateTime ZonedTime
- data RequestBodyEncoding
Documentation
data Configuration s Source #
An operation can and must be configured with data, which may be common for many operations.
This configuration consists of information about the server URL and the used security scheme.
In OpenAPI these information can be defined
- Root level
- Path level
- Operation level
To get started, the defaultConfiguration
can be used and changed accordingly.
Note that it is possible that BearerAuthenticationSecurityScheme
is not available because it is not a security scheme in the OpenAPI specification.
defaultConfiguration { configSecurityScheme = BearerAuthenticationSecurityScheme "token" }
Instances
doCallWithConfiguration Source #
:: (MonadHTTP m, SecurityScheme s) | |
=> Configuration s | Configuration options like base URL and security scheme |
-> Text | HTTP method (GET, POST, etc.) |
-> Text | Path to append to the base URL (path parameters should already be replaced) |
-> [(Text, Maybe String)] | Query parameters |
-> m (Either HttpException (Response ByteString)) | The raw response from the server |
This is the main functionality of this module
It makes a concrete Call to a Server without a body
doCallWithConfigurationM :: (MonadHTTP m, SecurityScheme s) => Text -> Text -> [(Text, Maybe String)] -> ReaderT (Configuration s) m (Either HttpException (Response ByteString)) Source #
Same as doCallWithConfiguration
but run in a ReaderT
environment which contains the configuration.
This is useful if multiple calls have to be executed with the same configuration.
doBodyCallWithConfiguration Source #
:: (MonadHTTP m, SecurityScheme s, ToJSON body) | |
=> Configuration s | Configuration options like base URL and security scheme |
-> Text | HTTP method (GET, POST, etc.) |
-> Text | Path to append to the base URL (path parameters should already be replaced) |
-> [(Text, Maybe String)] | Query parameters |
-> body | Request body |
-> RequestBodyEncoding | JSON or form data deepobjects |
-> m (Either HttpException (Response ByteString)) | The raw response from the server |
This is the main functionality of this module
It makes a concrete Call to a Server with a body
doBodyCallWithConfigurationM :: (MonadHTTP m, SecurityScheme s, ToJSON body) => Text -> Text -> [(Text, Maybe String)] -> body -> RequestBodyEncoding -> ReaderT (Configuration s) m (Either HttpException (Response ByteString)) Source #
Same as doBodyCallWithConfiguration
but run in a ReaderT
environment which contains the configuration.
This is useful if multiple calls have to be executed with the same configuration.
runWithConfiguration :: SecurityScheme s => Configuration s -> ReaderT (Configuration s) m a -> m a Source #
Run the ReaderT
monad with a specified configuration
Note: This is just
.flip
runReaderT
class Monad m => MonadHTTP m where Source #
Abstracts the usage of httpBS
away,
so that it can be used for testing
httpBS :: Request -> m (Either HttpException (Response ByteString)) Source #
Instances
MonadHTTP IO Source # | This instance is the default instance used for production code |
Defined in StripeAPI.Common httpBS :: Request -> IO (Either HttpException (Response ByteString)) Source # | |
MonadHTTP m => MonadHTTP (ReaderT r m) Source # | |
Defined in StripeAPI.Common httpBS :: Request -> ReaderT r m (Either HttpException (Response ByteString)) Source # |
stringifyModel :: StringifyModel a => a -> String Source #
Stringifies a showable value
>>>
stringifyModel "Test"
"Test"
>>>
stringifyModel 123
"123"
class Show a => StringifyModel a Source #
This type class makes the code generation for URL parameters easier as it allows to stringify a value
The Show
class is not sufficient as strings should not be stringified with quotes.
Instances
Show a => StringifyModel a Source # | |
Defined in StripeAPI.Common stringifyModel :: a -> String Source # | |
StringifyModel String Source # | |
Defined in StripeAPI.Common stringifyModel :: String -> String Source # |
class SecurityScheme s where Source #
Allows to specify an authentication scheme for requests done with doCallWithConfiguration
This can be used to define custom schemes as well
authenticateRequest :: s -> Request -> Request Source #
Instances
SecurityScheme AnonymousSecurityScheme Source # | Instance for the anonymous scheme which does not alter the request in any way |
Defined in StripeAPI.Common | |
SecurityScheme BearerAuthenticationSecurityScheme Source # | |
Defined in StripeAPI.SecuritySchemes | |
SecurityScheme BasicAuthenticationSecurityScheme Source # | |
Defined in StripeAPI.SecuritySchemes |
data AnonymousSecurityScheme Source #
The default authentication scheme which does not add any authentication information
Instances
SecurityScheme AnonymousSecurityScheme Source # | Instance for the anonymous scheme which does not alter the request in any way |
Defined in StripeAPI.Common |
textToByte :: Text -> ByteString Source #
Convert Text
a to ByteString
newtype JsonByteString Source #
Wraps a ByteString
to implement ToJSON
and FromJSON
Instances
newtype JsonDateTime Source #
Instances
data RequestBodyEncoding Source #
Defines how a request body is encoded
RequestBodyEncodingJSON | Encode the body as JSON |
RequestBodyEncodingFormData | Encode the body as form data |