{"id":18611586,"url":"https://github.com/robertdp/purescript-apiary","last_synced_at":"2025-06-22T17:33:21.458Z","repository":{"id":42175080,"uuid":"218209182","full_name":"robertdp/purescript-apiary","owner":"robertdp","description":"For the creation of type-level specs that can be queried against automatically. For full-stack specs, see https://github.com/robertdp/purescript-apiary-server","archived":false,"fork":false,"pushed_at":"2022-12-10T07:09:09.000Z","size":157,"stargazers_count":17,"open_issues_count":5,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-07T06:34:24.913Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PureScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robertdp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-29T05:14:41.000Z","updated_at":"2025-06-06T14:20:28.000Z","dependencies_parsed_at":"2023-01-26T04:30:55.245Z","dependency_job_id":null,"html_url":"https://github.com/robertdp/purescript-apiary","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/robertdp/purescript-apiary","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertdp%2Fpurescript-apiary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertdp%2Fpurescript-apiary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertdp%2Fpurescript-apiary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertdp%2Fpurescript-apiary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertdp","download_url":"https://codeload.github.com/robertdp/purescript-apiary/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertdp%2Fpurescript-apiary/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261333847,"owners_count":23143227,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T03:14:15.726Z","updated_at":"2025-06-22T17:33:16.438Z","avatar_url":"https://github.com/robertdp.png","language":"PureScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cpre\u003e\n    _          _\n   / \\   _ __ (_) __ _ _ __ _   _                .' '.            __\n  / _ \\ | '_ \\| |/ _` | '__| | | |      .        .   .           (__\\_\n / ___ \\| |_) | | (_| | |  | |_| |       .         .         . -{{_(|8)\n/_/   \\_\\ .__/|_|\\__,_|_|   \\__, |         ' .  . ' ' .  . '     (__/\n        |_|                 |___/\n\u003c/pre\u003e\n\nIt's hard to be a busy little bee when working with unspec'ed APIs. This library is designed for the creation of type-level specs that can be queried against automatically!\n\n### Example\n\n```purescript\ntype User\n  = { id :: Int\n    , name :: String\n    , email :: String\n    }\n\ntype ListUsers\n  = GET \"/users\"\n      { query ::\n        { sortBy :: UserSort\n        , sortDir :: SortDir\n        }\n      , response ::\n        { ok :: JSON (Array User)\n        }\n      }\n\ntype CreateNewUser\n  = POST \"/users\"\n      { body :: JSON { name :: String, email :: String }\n      , response ::\n        { ok :: JSON User\n        , badRequest :: JSON { errors :: Array { field :: String, message :: String } }\n        }\n      }\n\nlistUsers params =\n  Apiary.makeRequest (Route :: ListUsers) identity params none\n\ncreateNewUser body =\n  Apiary.makeRequest (Route :: CreateNewUser) identity none body\n```\n\nThis will give us inferred types equivalent to\n\n```purescript\nlistUsers ::\n  { sortBy :: Maybe UserSort, sortDir :: Maybe SortDir } -\u003e\n  Aff (Either Apiary.Error (Variant ( ok :: Array User )))\n\ncreateNewUser ::\n  { name :: String, email :: String } -\u003e\n  Aff\n    (Either Apiary.Error\n      (Variant\n        ( ok :: User\n        , badRequest :: { errors :: Array { field :: String, message :: String } }\n        )\n      )\n    )\n```\n\nHere is an example with URL modification and JWT-based authorisation inspired by some production code:\n\n```purescript\nmakeSecureRequest ::\n  forall m r route params body rep response.\n  MonadAff m =\u003e\n  MonadAsk { baseUrl :: String, token :: String | r } m =\u003e\n  Apiary.BuildRequest route params body rep =\u003e\n  Apiary.DecodeResponse rep response =\u003e\n  route -\u003e\n  params -\u003e\n  body -\u003e\n  m (Either Apiary.Error response)\nmakeSecureRequest route params body = do\n  env \u003c- ask\n  liftAff $ mkRequest (addBaseUrl env.baseUrl \u003c\u003c\u003c addToken env.token)\n  where\n\n  mkRequest modify =\n    Apiary.makeRequest route modify params body\n\n  addToken token request@{ headers } =\n    request { headers = Object.insert \"Authorization\" (\"Bearer \" \u003c\u003e token) headers }\n\n  addBaseUrl baseUrl request@{ url: URL url } =\n    request { url = URL (baseUrl \u003c\u003e url) }\n\ntype AppM = ReaderT { baseUrl :: String, token :: String } Aff\n\nlistUsers ::\n  { sortBy :: Maybe UserSort, sortDir :: Maybe SortDir } -\u003e\n  AppM (Either Apiary.Error (Variant ( ok :: Array User )))\nlistUsers params =\n  makeSecureRequest (Route :: ListUsers) params unit\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertdp%2Fpurescript-apiary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertdp%2Fpurescript-apiary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertdp%2Fpurescript-apiary/lists"}