github-rest
Query the GitHub REST API programmatically
https://github.com/brandonchinn178/github-rest#readme
| LTS Haskell 24.16: | 1.2.1 |
| Stackage Nightly 2025-10-24: | 1.2.1 |
| Latest on Hackage: | 1.2.1 |
github-rest-1.2.1@sha256:66687d80fcd7f7fd7b410ecc9616fa738833daa4920124533c28b5340290e5d6,2438Module documentation for 1.2.1
github-rest
A package providing a more flexible interface to accessing the GitHub API.
Endpoints are created using the GHEndpoint constructor and are executed with
the queryGitHub function in the GitHubT monad.
Quickstart
This quickstart will demonstrate querying endpoints in a hypothetical public
GitHub repo alice/my-project.
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
import Data.Text (Text)
import GitHub.REST
import Network.HTTP.Types (StdMethod(..))
default (Text)
main = do
let state = GitHubSettings
{ token = Nothing
-- ^ An authentication token to use, if any.
, userAgent = "alice/my-project"
-- ^ GitHub requires this to be set to a User Agent specific to your
-- application: https://developer.github.com/v3/#user-agent-required
, apiVersion = "v3"
-- ^ Specifies the API version to query: https://developer.github.com/v3/media/
}
runGitHubT state $ do
-- Get information for the "main" branch
-- https://developer.github.com/v3/git/refs/#get-a-single-reference
ref <- queryGitHub GHEndpoint
{ method = GET
-- Colon-prefixed components in the endpoint will be interpolated by
-- the values in 'endpointVals'.
-- In this case, "/repos/alice/my-project/git/refs/heads/main"
, endpoint = "/repos/:owner/:repo/git/refs/:ref"
, endpointVals =
[ "owner" := "alice"
, "repo" := "my-project"
, "ref" := "heads/main"
]
, ghData = []
}
-- 'github-rest' provides a '.:' helper for when the API guarantees that a
-- key in a JSON object exists
--
-- The result of 'queryGitHub' is anything that's an instance of FromJSON,
-- if using manually-defined data types is preferred over using '.:'. This
-- package can be easily used with the aeson-schemas library, which
-- provides a type-safe way to query JSON data.
let sha :: Text
sha = ref .: "object" .: "sha"
-- Create a new branch called "foo"
-- https://developer.github.com/v3/git/refs/#create-a-reference
queryGitHub GHEndpoint
{ method = POST
, endpoint = "/repos/:owner/:repo/git/refs"
, endpointVals =
[ "owner" := "alice"
, "repo" := "my-project"
]
, ghData =
[ "ref" := "refs/heads/foo"
, "sha" := sha
]
}
Comparison to other libraries
The github package provides a decent API for querying the GitHub API,
and it defines Haskell data types for each endpoint. These data types can
be used as the result of queryGitHub.
This package provides a different interface for people with different tastes:
-
github-restinforms the user exactly which GitHub endpoint is being hit (e.g./repos/:owner/:repo). Users no longer need to spend time trying to scour documentation to find the corresponding function for an endpoint. -
github-restpasses authentication once, with requests executed in a single monadic context. Thegithubpackage requires passing in an authentication token every time a request is executed -
In the same vein,
github-restprovides a monad transformer that handles all GitHub state needed to executequeryGitHub.githubruns everything inIO, expecting the caller to keep track of GitHub state manually. -
github-restallows usage withaeson-schemas
Changes
v1.2.1
- Make integration test more robust
v1.2.0
- Switch from
jwttojose-jwt+crypton- Removes the
loadSignerhelper, use normalcrypton/crypton-x509/crypton-x509-storeAPI
- Removes the
- Add support for GHC 9.8 + 9.10
- Drop support for GHC < 9.6
v1.1.4
- Fix a test failure due to GitHub changing URLs
v1.1.3
- Add support for GHC 9.4 + 9.6
- Drop support for GHC < 9
- Set the
X-GitHub-Api-Versionheader instead of setting the API version in theAcceptheader (#33)
v1.1.2
- Add support for
jwt-0.11.0
v1.1.1
- Add support for
aeson-2.0.0.0
v1.1.0
- Rename
GitHubStatetoGitHubSettings - Remove
queryGitHubPage'– implementqueryGitHubPageinMonadGitHubRESTinstead. - Expose
queryGitHubPageIOif users want to manually implementMonadGitHubREST - Add
DecodeErrorerror
v1.0.3
- Fix goldens after GitHub changed documentation URL
v1.0.2
- Remove
MonadFailconstraint onMonadGitHubREST - Support
unliftio-core-0.2.0.0
v1.0.1
Bundle test files in release tarball
v1.0.0
Initial release:
- Implement
queryGitHubandGHEndpoint - Implement
GitHubTandMonadGitHubREST