{"id":20230646,"url":"https://github.com/cdepillabout/envelope","last_synced_at":"2025-09-13T08:31:22.247Z","repository":{"id":62435916,"uuid":"55584618","full_name":"cdepillabout/envelope","owner":"cdepillabout","description":"Envelope type used to return responses from a JSON API for Haskell","archived":false,"fork":false,"pushed_at":"2017-04-19T06:25:10.000Z","size":19,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-20T02:19:32.138Z","etag":null,"topics":["envelope","haskell","json","json-api","response","wrapper"],"latest_commit_sha":null,"homepage":"https://hackage.haskell.org/package/envelope","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cdepillabout.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-06T07:24:27.000Z","updated_at":"2022-09-16T03:38:02.000Z","dependencies_parsed_at":"2022-11-01T21:16:55.954Z","dependency_job_id":null,"html_url":"https://github.com/cdepillabout/envelope","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/cdepillabout/envelope","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdepillabout%2Fenvelope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdepillabout%2Fenvelope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdepillabout%2Fenvelope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdepillabout%2Fenvelope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cdepillabout","download_url":"https://codeload.github.com/cdepillabout/envelope/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cdepillabout%2Fenvelope/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274937774,"owners_count":25377358,"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","status":"online","status_checked_at":"2025-09-13T02:00:10.085Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["envelope","haskell","json","json-api","response","wrapper"],"created_at":"2024-11-14T07:43:18.154Z","updated_at":"2025-09-13T08:31:22.224Z","avatar_url":"https://github.com/cdepillabout.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nWeb.Envelope\n============\n\n[![Build Status](https://secure.travis-ci.org/cdepillabout/envelope.svg)](http://travis-ci.org/cdepillabout/envelope)\n[![Hackage](https://img.shields.io/hackage/v/envelope.svg)](https://hackage.haskell.org/package/envelope)\n[![Stackage LTS](http://stackage.org/package/envelope/badge/lts)](http://stackage.org/lts/package/envelope)\n[![Stackage Nightly](http://stackage.org/package/envelope/badge/nightly)](http://stackage.org/nightly/package/envelope)\n![BSD3 license](https://img.shields.io/badge/license-BSD3-blue.svg)\n\nThis module exports an `Envelope` type that can be used to wrap reponses from a JSON REST API.  It provides a successful `Success` response, and a failure `Err` response.\n\nHere is a small demonstration of returning a success response:\n\n```haskell\n\u003e\u003e\u003e import qualified Data.ByteString.Lazy.Char8 as C8\n\u003e\u003e\u003e import Data.Aeson (decode, encode)\n\u003e\u003e\u003e let successEnvelope = toSuccessEnvelope 3 :: Envelope Text Int\n\u003e\u003e\u003e C8.putStrLn $ encode successEnvelope\n{\"data\":3}\n\u003e\u003e\u003e decode \"{\\\"data\\\":3}\" :: Maybe (Envelope Text Int)\nJust (EnvelopeSuccess (Success 3))\n```\n\nYour data gets wrapped in an object with a single `\"data\"` field:\n\n```json\n{\n    \"data\": 3\n}\n```\n\nNow lets look at how an error response is encoded and decoded.  It is encoded\nas an object with two members: @\\\"extra\\\"@ and @\\\"error\\\"@.\n\n```haskell\n\u003e\u003e\u003e let errorEnvelope = toErrEnvelope \"DB_ERROR\" \"there was an error in the database\" :: Envelope String Int\n\u003e\u003e\u003e C8.putStrLn $ encode errorEnvelope\n{\"extra\":\"there was an error in the database\",\"error\":\"DB_ERROR\"}\n\u003e\u003e\u003e decode \"{\\\"extra\\\":\\\"there was an error in the database\\\",\\\"error\\\":\\\"DB_ERROR\\\"}\" :: Maybe (Envelope String Int)\nJust (EnvelopeErr (Err {errErr = \"DB_ERROR\", errExtra = Just \"there was an error in the database\"}))\n```\n\nYour error type and extra message get wrapped in an object:\n\n```json\n{\n    \"extra\": \"there was an error in the database\",\n    \"error\": \"DB_ERROR\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdepillabout%2Fenvelope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcdepillabout%2Fenvelope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcdepillabout%2Fenvelope/lists"}