Skip to content

Commit

Permalink
docs(readme): update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Nassri committed Feb 27, 2021
1 parent 3fa38e8 commit b42a7fc
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RFC 7807 - Problem Details for HTTP APIs
[![test][test-img]][test-url]
[![semantic][semantic-img]][semantic-url]

> [RFC 7807 - Problem Details for HTTP APIs](https://tools.ietf.org/html/rfc7807)
> [RFC 7807 - Problem Details for HTTP APIs][]
## Install

Expand All @@ -20,12 +20,12 @@ npm install api-problem

### Constructor: `Problem(status[, title][, type][, members])`

| name | type | required | default | description | referece |
|---------------|----------|----------|--------------------|----------------------------------------------------------------------------------------|----------------------------------------------------------------|
| **`status`** | `String` | `` | `N/A` | The HTTP status code generated by the origin server for this occurrence of the problem | [Section 3.1](https://tools.ietf.org/html/rfc7807#section-3.1) |
| **`title`** | `String` | `` | HTTP status phrase | A short, human-readable summary of the problem type | [Section 3.1](https://tools.ietf.org/html/rfc7807#section-3.1) |
| **`type`** | `String` | `` | `about:blank` | A URI reference that identifies the problem type | [Section 3.1](https://tools.ietf.org/html/rfc7807#section-3.1) |
| **`details`** | `Object` | `` | `N/A` | additional details to attach to object | [Section 3.1](https://tools.ietf.org/html/rfc7807#section-3.2) |
| name | type | required | default | description | referece |
|---------------|----------|----------|--------------------|----------------------------------------------------------------------------------------|------------------|
| **`status`** | `String` | `` | `N/A` | The HTTP status code generated by the origin server for this occurrence of the problem | [Section 3.1][] |
| **`title`** | `String` | `` | HTTP status phrase | A short, human-readable summary of the problem type | [Section 3.1][] |
| **`type`** | `String` | `` | `about:blank` | A URI reference that identifies the problem type | [Section 3.1][] |
| **`details`** | `Object` | `` | `N/A` | additional details to attach to object | [Section 3.1][1] |

``` js
import Problem from 'api-problem'
Expand Down Expand Up @@ -85,7 +85,7 @@ prob.toString() //=> [403] You do not have enough credit ('https://example.com/p

### Method : `<void>` `send(response)`

uses [`response.writeHead`](https://nodejs.org/docs/latest/api/http.html#http_response_writehead_statuscode_statusmessage_headers) and [`response.end`](https://nodejs.org/docs/latest/api/http.html#http_response_end_data_encoding_callback) to send an appropriate error respnse message with the `Content-Type` response header to [`application/problem+json`](https://tools.ietf.org/html/rfc7807#section-3)
uses [`response.writeHead`][] and [`response.end`][] to send an appropriate error respnse message with the `Content-Type` response header to [`application/problem+json`][]

``` js
import http from 'http'
Expand All @@ -97,7 +97,7 @@ Problem.send(response)

### Express Middleware

A standard connect middleware is provided. The middleware intercepts Problem objects thrown as exceptions and serializes them appropriately in the HTTP response while setting the `Content-Type` response header to [`application/problem+json`](https://tools.ietf.org/html/rfc7807#section-3)
A standard connect middleware is provided. The middleware intercepts Problem objects thrown as exceptions and serializes them appropriately in the HTTP response while setting the `Content-Type` response header to [`application/problem+json`][]

``` js
import express from 'express'
Expand All @@ -113,6 +113,13 @@ app.get('/', (req, res) => {
app.use(Middleware)
```

[RFC 7807 - Problem Details for HTTP APIs]: https://tools.ietf.org/html/rfc7807
[Section 3.1]: https://tools.ietf.org/html/rfc7807#section-3.1
[1]: https://tools.ietf.org/html/rfc7807#section-3.2
[`response.writeHead`]: https://nodejs.org/docs/latest/api/http.html#http_response_writehead_statuscode_statusmessage_headers
[`response.end`]: https://nodejs.org/docs/latest/api/http.html#http_response_end_data_encoding_callback
[`application/problem+json`]: https://tools.ietf.org/html/rfc7807#section-3

----
> Author: [Ahmad Nassri](https://www.ahmadnassri.com/) &bull;
> Twitter: [@AhmadNassri](https://twitter.com/AhmadNassri)
Expand Down

0 comments on commit b42a7fc

Please sign in to comment.