github-0.14.1: Access to the GitHub API, v3.

MaintainerOleg Grenrus <>
Safe HaskellNone




This module provides data types and helper methods, which makes possible to build alternative API request intepreters in addition to provided IO functions.

Simple example using operational package. See samples/Operational/Operational.hs

type GithubMonad a = Program (GH.Request 'False) a

-- | Intepret GithubMonad value into IO
runMonad :: Manager -> GH.Auth -> GithubMonad a -> ExceptT GH.Error IO a
runMonad mgr auth m = case view m of
   Return a   -> return a
   req :>>= k -> do
       b <- ExceptT $ GH.executeRequestWithMgr mgr auth req
       runMonad mgr auth (k b)

-- | Lift request into Monad
githubRequest :: GH.Request 'False a -> GithubMonad a
githubRequest = singleton



data Request k a where Source

Github request data type.

  • k describes whether authentication is required. It's required for non-GET requests.
  • a is the result type

Note: Request is not Functor on purpose.


Query :: FromJSON a => Paths -> QueryString -> Request k a 
PagedQuery :: FromJSON (Vector a) => Paths -> QueryString -> Maybe Count -> Request k (Vector a) 
Command :: FromJSON a => CommandMethod a -> Paths -> ByteString -> Request True a 
StatusQuery :: StatusMap a -> Request k () -> Request k a 


data CommandMethod a where Source

Http method of requests with body.

Request execution in IO

executeRequest' :: Request False a -> IO (Either Error a) Source

Like executeRequest but without authentication.

executeRequestWithMgr' :: Manager -> Request False a -> IO (Either Error a) Source

Like executeRequestWithMgr but without authentication.

executeRequestMaybe :: Maybe Auth -> Request False a -> IO (Either Error a) Source

Helper for picking between executeRequest and executeRequest'.

The use is discouraged.

unsafeDropAuthRequirements :: Request True a -> Request k a Source

Partial function to drop authentication need.


makeHttpRequest :: MonadThrow m => Maybe Auth -> Request k a -> m Request Source

Create http-client Request.

parseResponse :: Maybe Auth -> Request k a -> Maybe Request

parseResponse :: (FromJSON a, MonadError Error m) => Response ByteString -> m a Source

Parse API response.

parseResponse :: FromJSON a => Response ByteString -> Either Error a

parseStatus :: MonadError Error m => StatusMap a -> Status -> m a Source

Helper for handling of RequestStatus.

parseStatus :: StatusMap a -> Status -> Either Error a

getNextUrl :: Response a -> Maybe URI Source

Query Link header with rel=next from the request headers.

performPagedRequest Source


:: (FromJSON a, Semigroup a, MonadCatch m, MonadError Error m) 
=> (Request -> m (Response ByteString))

httpLbs analogue

-> (a -> Bool)

predicate to continue iteration

-> Request

initial request

-> m a 

Helper for making paginated requests. Responses, a are combined monoidally.

performPagedRequest :: (FromJSON a, Semigroup a)
                    => (Request -> ExceptT Error IO (Response ByteString))
                    -> (a -> Bool)
                    -> Request
                    -> ExceptT Error IO a