Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Improved control flow with times and stopPropagation #202

Merged
merged 8 commits into from
Apr 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- [Route Handler](server/route-handler.md)
- [Request](server/request.md)
- [Response](server/response.md)
- [Event](server/event.md)

- Node Server

Expand Down
5 changes: 5 additions & 0 deletions docs/assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,8 @@ body .sidebar-toggle span:nth-child(3) {
.lang-json .token.property {
color: #e96900;
}

/****** COPY TO CLIPBOARD ******/
.docsify-copy-code-button {
font-size: 0.7em !important;
}
29 changes: 29 additions & 0 deletions docs/server/event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Event

## Properties

### type

_Type_: `String`

The event type. (e.g. `request`, `response`, `beforePersist`)

## Methods

### stopPropagation

If several event listeners are attached to the same event type, they are called in the order in which they were added. If `stopPropagation` is invoked during one such call, no remaining listeners will be called.

**Example**

```js
server.get('/session/:id').on('beforeResponse', (req, res, event) => {
event.stopPropagation();
res.setHeader('X-SESSION-ID', 'ABC123');
});

server.get('/session/:id').on('beforeResponse', (req, res, event) => {
// This will never be reached
res.setHeader('X-SESSION-ID', 'XYZ456');
});
```
6 changes: 6 additions & 0 deletions docs/server/events-and-middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Fires right before the request goes out.
| Param | Type | Description |
| ----- | ------------------------- | -------------------- |
| req | [Request](server/request) | The request instance |
| event | [Event](server/event) | The event instance |

**Example**

Expand All @@ -60,6 +61,7 @@ Fires right before the response materializes and the promise resolves.
| ----- | --------------------------- | --------------------- |
| req | [Request](server/request) | The request instance |
| res | [Response](server/response) | The response instance |
| event | [Event](server/event) | The event instance |

**Example**

Expand All @@ -78,6 +80,7 @@ the response materializes and the promise resolves.
| ----- | --------------------------- | --------------------- |
| req | [Request](server/request) | The request instance |
| res | [Response](server/response) | The response instance |
| event | [Event](server/event) | The event instance |

**Example**

Expand All @@ -97,6 +100,7 @@ Fires before the request/response gets persisted.
| --------- | ------------------------- | ------------------------------------ |
| req | [Request](server/request) | The request instance |
| recording | `Object` | The recording that will be persisted |
| event | [Event](server/event) | The event instance |

**Example**

Expand All @@ -116,6 +120,7 @@ and before the recording materializes into a response.
| --------- | ------------------------- | ----------------------- |
| req | [Request](server/request) | The request instance |
| recording | `Object` | The retrieved recording |
| event | [Event](server/event) | The event instance |

**Example**

Expand All @@ -134,6 +139,7 @@ Fires when any error gets emitted during the request life-cycle.
| ----- | ------------------------- | -------------------- |
| req | [Request](server/request) | The request instance |
| error | Error | The error |
| event | [Event](server/event) | The event instance |

**Example**

Expand Down
170 changes: 85 additions & 85 deletions docs/server/request.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,90 @@
# Request

## Properties

### method

_Type_: `String`

The request method. (e.g. `GET`, `POST`, `DELETE`)

### url

_Type_: `String`

The request URL.

### protocol

_Type_: `String`

The request url protocol. (e.g. `http://`, `https:`)

### hostname

_Type_: `String`

The request url host name. (e.g. `localhost`, `netflix.com`)

### port

_Type_: `String`

The request url port. (e.g. `3000`)

### pathname

_Type_: `String`

The request url path name. (e.g. `/session`, `/movies/1`)

### hash

_Type_: `String`

The request url hash.

### headers

_Type_: `Object`
_Default_: `{}`

The request headers.

### body

_Type_: `any`

The request body.

### query

_Type_: `Object`
_Default_: `{}`

The request url query parameters.

### params

_Type_: `Object`
_Default_: `{}`

The matching route's path params.

**Example**

```js
server.get('/movies/:id').intercept((req, res) => {
console.log(req.params.id);
});
```

### recordingName

_Type_: `String`

The recording the request should be recorded under.

## Methods

### getHeader
Expand Down Expand Up @@ -161,88 +246,3 @@ A shortcut method that calls JSON.parse on the request's body.
```js
req.jsonBody();
```

## Properties

### method

_Type_: `String`

The request method. (e.g. `GET`, `POST`, `DELETE`)

### url

_Type_: `String`

The request URL.

### protocol

_Type_: `String`

The request url protocol. (e.g. `http://`, `https:`)

### hostname

_Type_: `String`

The request url host name. (e.g. `localhost`, `netflix.com`)

### port

_Type_: `String`

The request url port. (e.g. `3000`)

### pathname

_Type_: `String`

The request url path name. (e.g. `/session`, `/movies/1`)

### hash

_Type_: `String`

The request url hash.

### headers

_Type_: `Object`
_Default_: `{}`

The request headers.

### body

_Type_: `any`

The request body.

### query

_Type_: `Object`
_Default_: `{}`

The request url query parameters.

### params

_Type_: `Object`
_Default_: `{}`

The matching route's path params.

**Example**

```js
server.get('/movies/:id').intercept((req, res) => {
console.log(req.params.id);
});
```

### recordingName

_Type_: `String`

The recording the request should be recorded under.
Loading