2022-05-05 15:51:43 +00:00
# HTTPurple 🪁
2017-05-25 19:12:29 +00:00
2022-05-05 15:51:43 +00:00
[![License ](https://img.shields.io/badge/license-MIT-blue.svg )](https://raw.githubusercontent.com/sigma-andex/purescript-httpurple/main/License)
2022-06-11 17:06:27 +00:00
[![purescript-httpurple on Pursuit ](https://pursuit.purescript.org/packages/purescript-httpurple/badge )](https://pursuit.purescript.org/packages/purescript-httpurple)
2017-07-10 19:38:56 +00:00
2022-06-13 14:31:39 +00:00
A functional http framework with a focus on type-safety and making the common case easy.
2017-05-25 19:12:29 +00:00
2022-06-13 14:31:39 +00:00
This project was originally forked from the amazing [HTTPure ](https://github.com/citizennet/purescript-httpure ) http server framework, but has since deviated quite a bit. If you are coming from HTTPure you might want to have a look at the [differences to HTTPure ](./docs/Differences.md ).
2022-05-22 17:39:34 +00:00
## ToC
2022-06-13 14:30:03 +00:00
1. [Features ](#features )
2022-05-22 17:39:34 +00:00
1. [Installation ](#installation )
1. [Quick start ](#quick-start )
1. [Documenation ](#documentation )
1. [Examples ](#examples )
1. [Testing ](#testing )
1. [License ](#license )
2017-05-25 19:12:29 +00:00
2022-06-13 14:30:03 +00:00
## Features
* λ fp-style http server & request handlers
* 🛣 Powerful & type-safe routing dsl
* 🕵🏻♂️ Easy json parsing and data validation
2022-08-25 10:53:59 +00:00
* 🥪 Supports Node/Express middlewares
2022-06-13 14:30:03 +00:00
* 📜 Extensive documentation & examples
2017-05-25 19:12:29 +00:00
## Installation
```bash
2022-05-22 11:47:58 +00:00
spago install httpurple
2017-05-25 19:12:29 +00:00
```
2022-05-22 17:39:34 +00:00
## Quick start
2017-07-10 10:17:13 +00:00
```purescript
module Main where
2022-05-22 16:54:11 +00:00
import Prelude hiding ((/))
2017-07-10 10:17:13 +00:00
2022-05-25 18:11:39 +00:00
import HTTPurple
2022-05-22 16:54:11 +00:00
data Route = Hello String
derive instance Generic Route _
route :: RouteDuplex' Route
2022-05-25 18:11:39 +00:00
route = mkRoute
2022-05-22 16:54:11 +00:00
{ "Hello": "hello" / segment
}
2017-07-10 10:17:13 +00:00
2021-11-19 06:16:35 +00:00
main :: ServerM
2022-05-22 16:54:11 +00:00
main =
serve { port: 8080 } { route, router }
2017-07-10 10:17:13 +00:00
where
2022-05-22 16:54:11 +00:00
router { route: Hello name } = ok $ "hello " < > name
```
then start the server
```bash
➜ spago run
Src Lib All
Warnings 0 0 0
Errors 0 0 0
[info] Build succeeded.
HTTPurple 🪁 up and running on http://0.0.0.0:8080
```
query your server, e.g. using [httpie ](https://httpie.io/ )
```bash
➜ http http://localhost:8080/hello/🗺
HTTP/1.1 200 OK
Connection: keep-alive
Content-Length: 10
Date: Sun, 22 May 2022 16:50:52 GMT
Keep-Alive: timeout=5
hello 🗺
2017-07-10 10:17:13 +00:00
```
2017-05-25 19:12:29 +00:00
## Documentation
2022-06-11 16:47:45 +00:00
See the [docs folder ](./docs ) for the in-depth guides.
* [Basics ](./docs/Basics.md ) - Basic introduction to HTTPurple 🪁
* [Routing ](./docs/Routing.md ) - Explanation of the routing dsl
* [Requests ](./docs/Requests.md ) - Guide to request handling
* [Response ](./docs/Responses.md ) - Guide to response handling
* [Differences ](./docs/Differences.md ) - A detailed description of the differences to HTTPure
2017-10-26 20:28:47 +00:00
2017-07-10 10:17:13 +00:00
## Examples
2022-05-22 11:47:58 +00:00
HTTPurple ships with a number of [examples ](./docs/Examples ). To run an example,
2017-10-26 20:28:47 +00:00
in the project root, run:
2017-07-10 10:17:13 +00:00
2021-11-17 05:50:23 +00:00
```bash
spago -x test.dhall run --main Examples.< Example Name > .Main
2017-07-10 10:17:13 +00:00
```
2017-05-25 19:12:29 +00:00
2017-07-10 10:17:13 +00:00
Each example's startup banner will include information on routes available on
the example server.
2017-05-25 19:12:29 +00:00
## Testing
2017-07-10 10:17:13 +00:00
To run the test suite, in the project root run:
2017-05-25 19:12:29 +00:00
```bash
2022-05-05 15:51:43 +00:00
spago -x test.dhall test
2017-05-25 19:12:29 +00:00
```
## License
2022-05-22 11:47:58 +00:00
This is a fork of [HTTPure ](https://github.com/citizennet/purescript-httpure ), which is licensed under MIT. See the [original license ](./LICENSES/httpure.LICENSE ). This work is similarly licensed under [MIT ](./License ).