Skip to content

Commit

Permalink
Version 4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaq committed Apr 2, 2021
1 parent dbe001d commit b4123aa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright (c) 2020 Aldwin Vlasblom
Copyright (c) 2021 Aldwin Vlasblom

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand Down
47 changes: 32 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,34 @@

Create Express middleware using Futures from [Fluture][].

## Usage

```sh
npm install --save fluture fluture-express
```

Allows for the definition of pure functions to be used as Express
middleware. This has benefits for testing and developer sanity.
Another benefit of this particular approach, where every middleware is
wrapped individually, is that it plays nicely with existing Express
middleware, and they can be used interchangably.

## Usage

### Node

```console
$ npm install --save fluture-express
```

On Node 12 and up, this module can be loaded directly with `import` or
`require`. On Node versions below 12, `require` or the [esm][]-loader can
be used.

### Deno and Modern Browsers

You can load the EcmaScript module from various content delivery networks:

- [Skypack](https://cdn.skypack.dev/fluture-express@0.0.0)
- [JSPM](https://jspm.dev/fluture-express@0.0.0)
- [jsDelivr](https://cdn.jsdelivr.net/npm/fluture-express@0.0.0/+esm)

### Usage Example

```js
// index.js

Expand Down Expand Up @@ -61,48 +77,48 @@ Fluture-Express mutates the response object for you, based on a
specification of what the response should be. This specification is
captured by the Response sum-type.

#### <a name="Response" href="https://github.com/fluture-js/fluture-express/blob/v4.0.0/index.js#L120">`Response :: Type`</a>
#### <a name="Response" href="https://github.com/fluture-js/fluture-express/blob/v4.1.0/index.js#L136">`Response :: Type`</a>

The [daggy][] type representative of the Response type. You'll want to
use one of its constructors listed below most of the time.

#### <a name="Stream" href="https://github.com/fluture-js/fluture-express/blob/v4.0.0/index.js#L133">`Stream :: Number -⁠> String -⁠> NodeReadableStream -⁠> Response a`</a>
#### <a name="Stream" href="https://github.com/fluture-js/fluture-express/blob/v4.1.0/index.js#L149">`Stream :: Number -⁠> String -⁠> NodeReadableStream -⁠> Response a`</a>

Indicates a streamed response. The first argument will be the response
status code, the second will be used as a mime type, and the third will be
piped into the response to form the response data.

#### <a name="Json" href="https://github.com/fluture-js/fluture-express/blob/v4.0.0/index.js#L142">`Json :: Number -⁠> Object -⁠> Response a`</a>
#### <a name="Json" href="https://github.com/fluture-js/fluture-express/blob/v4.1.0/index.js#L158">`Json :: Number -⁠> Object -⁠> Response a`</a>

Indicates a JSON response. The first argument will be the response status
code, and the second will be converted to JSON and sent as-is.

#### <a name="Render" href="https://github.com/fluture-js/fluture-express/blob/v4.0.0/index.js#L150">`Render :: Number -⁠> String -⁠> Object -⁠> Response a`</a>
#### <a name="Render" href="https://github.com/fluture-js/fluture-express/blob/v4.1.0/index.js#L166">`Render :: Number -⁠> String -⁠> Object -⁠> Response a`</a>

Indicates a response to be rendered using a template. The first argument
will be the response status code, the second is the path to the template
file, and the third is the data to inject into the template. This uses
Express' render method under the hood, so you can configure it globally
with `app.set ('view engine', engine)` and `app.set ('views', path)`.

#### <a name="Redirect" href="https://github.com/fluture-js/fluture-express/blob/v4.0.0/index.js#L161">`Redirect :: Number -⁠> String -⁠> Response a`</a>
#### <a name="Redirect" href="https://github.com/fluture-js/fluture-express/blob/v4.1.0/index.js#L177">`Redirect :: Number -⁠> String -⁠> Response a`</a>

Indicates a redirection. The first argument will be the response status
code, and the second will be the value of the Location header.

#### <a name="Empty" href="https://github.com/fluture-js/fluture-express/blob/v4.0.0/index.js#L169">`Empty :: Response a`</a>
#### <a name="Empty" href="https://github.com/fluture-js/fluture-express/blob/v4.1.0/index.js#L185">`Empty :: Response a`</a>

Indicates an empty response. The response status will be set to 204, and
no response body or Content-Type header will be sent.

#### <a name="Next" href="https://github.com/fluture-js/fluture-express/blob/v4.0.0/index.js#L175">`Next :: a -⁠> Response a`</a>
#### <a name="Next" href="https://github.com/fluture-js/fluture-express/blob/v4.1.0/index.js#L191">`Next :: a -⁠> Response a`</a>

Indicates that this middleware does not form a response. The supplied value
will be assigned to `res.locals` and the next middleware will be called.

### Middleware creation utilities

#### <a name="middleware" href="https://github.com/fluture-js/fluture-express/blob/v4.0.0/index.js#L183">`middleware :: ((Req, a) -⁠> Future b (Response a)) -⁠> (Req, Res a, (b -⁠> Undefined)) -⁠> Undefined`</a>
#### <a name="middleware" href="https://github.com/fluture-js/fluture-express/blob/v4.1.0/index.js#L199">`middleware :: ((Req, a) -⁠> Future b (Response a)) -⁠> (Req, Res a, (b -⁠> Undefined)) -⁠> Undefined`</a>

Converts an action to an Express middleware.

Expand All @@ -113,7 +129,7 @@ appropriate mutations to the [`res`][].
If the Future rejects, the rejection reason is passed into `next` for
further [error handling with Express][].

#### <a name="dispatcher" href="https://github.com/fluture-js/fluture-express/blob/v4.0.0/index.js#L197">`dispatcher :: String -⁠> String -⁠> (Req, Res a, (Any -⁠> Undefined)) -⁠> Promise Undefined`</a>
#### <a name="dispatcher" href="https://github.com/fluture-js/fluture-express/blob/v4.1.0/index.js#L213">`dispatcher :: String -⁠> String -⁠> (Req, Res a, (Any -⁠> Undefined)) -⁠> Promise Undefined`</a>

Creates middleware that uses the export from the given file in the given
directory as an "action".
Expand All @@ -131,3 +147,4 @@ The exported value should be a function of the same signature as given to
[`res`]: #res-a
[error handling with Express]: https://expressjs.com/en/guide/error-handling.html
[daggy]: https://github.com/fantasyland/daggy
[esm]: https://github.com/standard-things/esm
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fluture-express",
"version": "4.0.0",
"version": "4.1.0",
"description": "Create Express middleware using Futures",
"keywords": [
"fluture",
Expand Down

0 comments on commit b4123aa

Please sign in to comment.