From cae3688f37d1672655032b2fa9249866a29cd0d9 Mon Sep 17 00:00:00 2001 From: Ahmad Nassri Date: Mon, 8 Feb 2021 19:09:11 -0500 Subject: [PATCH] docs(readme): update readme --- README.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 885a8e6..dab5cac 100644 --- a/README.md +++ b/README.md @@ -34,17 +34,14 @@ import Problem from 'api-problem' new Problem(404) //=> { status: '404', title: 'Not Found', type: 'https://httpstatuses.com/404' } - // override defaults new Problem(404, 'Oops! Page Not Found') //=> { status: '404', title: 'Oops! Page Not Found', type: 'https://httpstatuses.com/404' } - // custom values new Problem(403, 'You do not have enough credit', 'https://example.com/probs/out-of-credit') //=> { status: '403', title: 'You do not have enough credit', type: 'https://example.com/probs/out-of-credit' } - // additional details new Problem(403, 'You do not have enough credit', 'https://example.com/probs/out-of-credit', { detail: 'Your current balance is 30, but that costs 50.', @@ -55,7 +52,6 @@ new Problem(403, 'You do not have enough credit', 'https://example.com/probs/out //=> { status: '403', title: 'You do not have enough credit', type: 'https://example.com/probs/out-of-credit', detail: 'Your current balance is 30, but that costs 50.', instance: '/account/12345/msgs/abc', balance: 30, accounts: ['/account/12345', '/account/67890'] } - // HTTP defaults + Details new Problem(403, { detail: 'Account suspended', @@ -63,10 +59,11 @@ new Problem(403, { date: '2016-01-15T06:47:01.175Z', account_id: '12345' }) + //=> { status: '403', title: 'Forbidden', type: 'https://httpstatuses.com/404', detail: 'Account suspended', instance: '/account/12345', account_id: 12345, 'date: 2016-01-15T06:47:01.175Z' } ``` -### Method : `toObject()` +### Method : `` `toObject()` returns an object containing all the properties including: *(status, title, type, members)* @@ -76,7 +73,7 @@ const prob = new Problem(403, 'You do not have enough credit', 'https://example. prob.toObject() //=> { status: 403, title: 'You do not have enough credit', type: 'https://example.com/probs/out-of-credit', user_id: 'x123' } ``` -### Method : `toString()` +### Method : `` `toString()` returns a simplified, human-readable string representation @@ -86,7 +83,7 @@ const prob = new Problem(403, 'You do not have enough credit', 'https://example. prob.toString() //=> [403] You do not have enough credit ('https://example.com/probs/out-of-credit') ``` -### Method : `send(response)` +### Method : `` `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`\]\[spec-3\]