Skip to content

Build and scale financial applications faster on IEX Cloud and correctly with Haskell.

Notifications You must be signed in to change notification settings

JamesCarl/iex-haskell-sdk

Repository files navigation

Semi-OpenAPI Auto-Generated http-client Bindings to IEX Haskell SDK

Build Status

The library in lib provides mostly auto-generated-from-OpenAPI http-client bindings to the IEX Haskell SDK API.

Installation

Installation follows the standard approach to installing Stack-based projects.

  1. Install the Haskell stack tool.
  2. To build the package, and generate the documentation (recommended):
stack haddock

which will generate docs for this lib in the docs folder.

To generate the docs in the normal location (to enable hyperlinks to external libs), remove

build:
  haddock-arguments:
    haddock-args:
    - "--odir=./docs"

from the stack.yaml file and run stack haddock again.

  1. To run unit tests:
stack test

Modules

MODULE NOTES
IEXHaskellSDK.Client use the "dispatch" functions to send requests
IEXHaskellSDK.Core core funcions, config and request types
IEXHaskellSDK.API construct api requests
IEXHaskellSDK.Model describes api models
IEXHaskellSDK.MimeTypes encoding/decoding MIME types (content-types/accept)
IEXHaskellSDK.ModelLens lenses for model fields
IEXHaskellSDK.Logging logging functions and utils

MimeTypes

This library adds type safety around what OpenAPI specifies as Produces and Consumes for each Operation (e.g. the list of MIME types an Operation can Produce (using 'accept' headers) and Consume (using 'content-type' headers).

For example, if there is an Operation named addFoo, there will be a data type generated named AddFoo (note the capitalization), which describes additional constraints and actions on the addFoo operation via its typeclass instances. These typeclass instances can be viewed in GHCi or via the Haddocks.

  • required parameters are included as function arguments to addFoo
  • optional non-body parameters are included by using applyOptionalParam
  • optional body parameters are set by using setBodyParam

Example code generated for pretend addFoo operation:

data AddFoo 	
instance Consumes AddFoo MimeJSON
instance Produces AddFoo MimeJSON
instance Produces AddFoo MimeXML
instance HasBodyParam AddFoo FooModel
instance HasOptionalParam AddFoo FooName
instance HasOptionalParam AddFoo FooId

this would indicate that:

  • the addFoo operation can consume JSON
  • the addFoo operation produces JSON or XML, depending on the argument passed to the dispatch function
  • the addFoo operation can set it's body param of FooModel via setBodyParam
  • the addFoo operation can set 2 different optional parameters via applyOptionalParam

If the OpenAPI spec doesn't declare it can accept or produce a certain MIME type for a given Operation, you should either add a Produces or Consumes instance for the desired MIME types (assuming the server supports it), use dispatchLbsUnsafe or modify the OpenAPI spec and run the generator again.

New MIME type instances can be added via MimeType/MimeRender/MimeUnrender

Only JSON instances are generated by default, and in some case x-www-form-urlencoded instances (FromFrom, ToForm) will also be generated if the model fields are primitive types, and there are Operations using x-www-form-urlencoded which use those models.

Authentication

A haskell data type will be generated for each OpenAPI authentication type.

If for example the AuthMethod AuthOAuthFoo is generated for OAuth operations, then addAuthMethod should be used to add the AuthMethod config.

When a request is dispatched, if a matching auth method is found in the config, it will be applied to the request.

Example

mgr <- newManager defaultManagerSettings
config0 <- withStdoutLogging =<< newConfig 
let config = config0
    `addAuthMethod` AuthOAuthFoo "secret-key"

let addFooRequest = 
  addFoo 
    (ContentType MimeJSON) 
    (Accept MimeXML) 
    (ParamBar paramBar)
    (ParamQux paramQux)
    modelBaz
  `applyOptionalParam` FooId 1
  `applyOptionalParam` FooName "name"
  `setHeader` [("qux_header","xxyy")]
addFooResult <- dispatchMime mgr config addFooRequest

See the example app and the haddocks for details.

About

Build and scale financial applications faster on IEX Cloud and correctly with Haskell.

Resources

Stars

Watchers

Forks

Packages

No packages published