Skip to content

Commit

Permalink
feat: 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
asos-craigmorten committed May 23, 2020
1 parent 9c3eefc commit a394ddb
Show file tree
Hide file tree
Showing 75 changed files with 3,074 additions and 3,416 deletions.
128 changes: 128 additions & 0 deletions .github/API/bodyparser.md

Large diffs are not rendered by default.

28 changes: 24 additions & 4 deletions .github/API/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,32 @@ When a request is made to `/greet/jp`, `req.baseUrl` is "/greet". When a request

#### req.body

Contains the data submitted in the request body. By default the `req.body` is a `Deno.Reader`, and needs to be read using a body-parsing middleware. Opine plans to support and export standard body-parsing middlewares, but currently consumers will need to handle the parsing of the body themselves.
Contains the data submitted in the request body. By default the `req.body` is a `Deno.Reader`, and needs to be read using a body-parsing middleware such as [`json()`](./bodyParser.md) or [`urlencoded()`](./bodyParser.md).

The following example shows how to use a simple body-parsing middleware to transform `req.body` into a raw string:
The following example shows how to use body-parsing middleware to populate `req.body`.

```ts
const opine = require("opine");
import {
opine,
json,
urlencoded,
} from "https://deno.land/x/opine@master/mod.ts";

const app = opine();

app.use(json()); // for parsing application/json
app.use(urlencoded(); // for parsing application/x-www-form-urlencoded

app.post("/profile", function (req, res, next) {
console.log(req.body);
res.json(req.body);
});
```
The following example shows how to implement your own simple body-parsing middleware to transform `req.body` into a raw string:
```ts
import opine from "https://deno.land/x/opine@master/mod.ts";

const app = opine();

Expand All @@ -89,7 +109,7 @@ const bodyParser = async function (req, res, next) {
const rawBody = await Deno.readAll(req.body);
const decodedBody = decoder.decode(rawBody);

req.body = decodedBody;
(req as any).body = decodedBody;
}
};

Expand Down
2 changes: 1 addition & 1 deletion .github/API/router.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A router behaves like middleware itself, so you can use it as an argument to [ap

Opine has a top-level named function export `Router()` that creates a new `router` object.

```js
```ts
import { Router } from "https://deno.land/x/opine@master/mod.ts";

const router = Router(options);
Expand Down
6 changes: 6 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ChangeLog

## [0.2.0] - 23-05-2020

### Added

- `json`, `text`, `raw` and `urlencoded` body parser middlewares.

## [0.1.0] - 23-05-2020

### Added
Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: benchmark build ci doc fmt fmt-check update-lock test typedoc
.PHONY: benchmark build ci doc fmt fmt-check precommit test typedoc update-lock

benchmark:
@./benchmarks/run.sh 1 ./benchmarks/middleware.ts
Expand Down Expand Up @@ -28,11 +28,18 @@ fmt:
fmt-check:
@deno fmt --check

update-lock:
@deno run --lock=lock.json --lock-write --reload mod.ts
precommit:
@make typedoc
@make fmt
@make fmt
@make fmt
@make update-lock

test:
@deno test --allow-net ./test/units/

typedoc:
@typedoc --ignoreCompilerErrors --out ./docs --mode modules --includeDeclarations --excludeExternals --includes ./typings/index.d.ts ./src

update-lock:
@deno run --lock=lock.json --lock-write --reload mod.ts
6 changes: 5 additions & 1 deletion deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ export {
Evt as EventEmitter,
to as getEvent,
} from "https://deno.land/x/evt@v1.6.8/mod.ts";
export { contentType } from "https://deno.land/x/media_types@v2.3.1/mod.ts";
export {
contentType,
charset,
} from "https://deno.land/x/media_types@v2.3.1/mod.ts";
export { createHttpError } from "https://deno.land/x/oak@v4.0.0/httpError.ts";
2 changes: 1 addition & 1 deletion docs/assets/js/search.json

Large diffs are not rendered by default.

Loading

0 comments on commit a394ddb

Please sign in to comment.