{"id":17084528,"url":"https://github.com/nsaunders/purescript-nodetrout","last_synced_at":"2025-03-23T13:49:49.104Z","repository":{"id":54578197,"uuid":"209822146","full_name":"nsaunders/purescript-nodetrout","owner":"nsaunders","description":"Build a Node HTTP server with Trout.","archived":false,"fork":false,"pushed_at":"2020-11-04T18:19:36.000Z","size":114,"stargazers_count":8,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T23:17:06.152Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nsaunders.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":"2019-09-20T15:22:42.000Z","updated_at":"2023-09-18T22:01:23.000Z","dependencies_parsed_at":"2022-08-13T20:20:31.264Z","dependency_job_id":null,"html_url":"https://github.com/nsaunders/purescript-nodetrout","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsaunders%2Fpurescript-nodetrout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsaunders%2Fpurescript-nodetrout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsaunders%2Fpurescript-nodetrout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nsaunders%2Fpurescript-nodetrout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nsaunders","download_url":"https://codeload.github.com/nsaunders/purescript-nodetrout/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245111928,"owners_count":20562511,"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-10-14T13:07:50.645Z","updated_at":"2025-03-23T13:49:49.078Z","avatar_url":"https://github.com/nsaunders.png","language":"PureScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# purescript-nodetrout [![build status](https://img.shields.io/travis/nsaunders/purescript-nodetrout.svg)](https://travis-ci.org/nsaunders/purescript-nodetrout) [![purescript-nodetrout on Pursuit](https://pursuit.purescript.org/packages/purescript-nodetrout/badge)](https://pursuit.purescript.org/packages/purescript-nodetrout) [![nodetrout in package-sets](https://img.shields.io/endpoint.svg?url=https://package-sets-badge-zxa7vacp3dju.runkit.sh/nodetrout)](https://github.com/purescript/package-sets)\n## Build a Node HTTP server with Trout.\n\n\u003cimg src=\"https://raw.githubusercontent.com/nsaunders/purescript-nodetrout/master/img/readme-tile.png\" alt=\"purescript-nodetrout\" align=\"right\" /\u003e\n\n[Trout](https://github.com/purescript-hyper/purescript-trout) is a type-level routing DSL. Similar to Haskell's [Servant](https://github.com/haskell-servant/servant) library, Trout allows routes to be specified as a data type. Given this data type along with a [record](https://github.com/purescript/documentation/blob/master/language/Records.md) of corresponding handlers, this library can produce a [`node-http`](https://github.com/purescript-node/purescript-node-http) request handler of type `Request -\u003e Response -\u003e Effect Unit`, which [can then be used to create an HTTP server](https://pursuit.purescript.org/packages/purescript-node-http/5.0.2/docs/Node.HTTP#v:createServer).\n\n### An API in 4 simple steps\n1. Specify routes as a data type. Here, we create a `GET /admin` route that requires a Basic Authorization header and responds with a greeting:\n```purescript\ntype Site = \"admin\" := \"admin\" :/ Header \"Authorization\" BasicAuth :\u003e Resource (Get Greeting JSON)\n```\n\n2. Create a [`Proxy`](https://pursuit.purescript.org/packages/purescript-proxy/3.0.0/docs/Type.Proxy) value to capture the route specifications:\n```purescript\nsite :: Proxy Site\nsite = Proxy\n```\n\n3. Define a handler for each route. Here, we greet the user by the username specified in the Basic Authorization header:\n```purescript\nresources :: forall m. Monad m =\u003e { admin :: BasicAuth -\u003e { \"GET\" :: ExceptT HTTPError m Greeting } }\nresources = { admin: \\auth -\u003e { \"GET\": pure $ Greeting $ \"Hello, \" \u003c\u003e (fst $ un BasicAuth auth) } }\n```\n\n4. Serve the API using `node-http`:\n```purescript\nmain :: Effect Unit\nmain = do\n  server \u003c- createServer $ serve' site resources (const $ pure unit)\n  listen server { hostname: \"0.0.0.0\", port: 3000, backlog: Nothing } $ log \"Listening on port 3000...\"\n```\n\n### Installation\n\n[bower](https://github.com/bower/bower):\n```\nbower install --save purescript-nodetrout\n```\n\n[psc-package](https://github.com/purescript/psc-package):\n```\npsc-package install nodetrout\n```\n\n[spago](https://github.com/spacchetti/spago):\n```\nspago install nodetrout\n```\n\n### Examples\n\nA number of usage examples are available [here](example).\n\nTo run the examples, clone the repository and run one of the following depending on your package manager and build tool, replacing `\u003cexample-name\u003e` with the name of one of the examples.\n\n[bower](https://github.com/bower/bower) + [pulp](http://github.com/purescript-contrib/pulp):\n```\nbower install\npulp run -I example -m Example.\u003cexample-name\u003e\n```\n\n[spago](https://github.com/spacchetti/spago):\n```\nspago run -p example/\u003cexample-name\u003e.purs -m Example.\u003cexample-name\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsaunders%2Fpurescript-nodetrout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnsaunders%2Fpurescript-nodetrout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnsaunders%2Fpurescript-nodetrout/lists"}