Skip to content

Commit 250bf40

Browse files
Dragomir-Ivanovsmyrman
authored andcommitted
Refactor README.md
1 parent 6552382 commit 250bf40

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

README.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ The REST Layer framework is composed of several sub-packages:
6565
- [Data Validation](#data-validation)
6666
- [Nullable Values](#nullable-values)
6767
- [Extensible Data Validation](#extensible-data-validation)
68-
- [JSON Patch](#json-patch)
6968
- [Timeout and Request Cancellation](#timeout-and-request-cancellation)
7069
- [Logging](#logging)
7170
- [CORS](#cors)
@@ -1201,11 +1200,23 @@ Used to query a resource with its sub/embedded resources.
12011200
Used to create new resource document, where new `ID` is generated from the server.
12021201
12031202
### PUT
1204-
Used to create/update single resource document given its `ID`.\
1205-
Be aware when dealing with resource fields with `Default` set. Initial creation for such resources will set particular field to its default value if omitted, however on subsequent `PUT` calls this field will be deleted if omitted. If persistent `Default` field is needed use `{Required: true}` with it.
1203+
Used to create/update single resource document given its `ID`. Be aware when dealing with resource fields with `Default` set. Initial creation for such resources will set particular field to its default value if omitted, however on subsequent `PUT` calls this field will be deleted if omitted. If persistent `Default` field is needed use `{Required: true}` with it.
12061204
12071205
### PATCH
1208-
Used to update/patch single resource document given its `ID`.
1206+
Used to update/patch single resource document given its `ID`. REST Layer supports following update protocols:
1207+
1208+
- Simple filed replacement [RFC-5789](http://tools.ietf.org/html/rfc5789) - this protocol will udpate only supplied top level fields, and will leave other fields in the document intact. This means that this protocol can't delete fields. Using this protocol is specified with `Content-Type: application/json` HTTP Request header.
1209+
1210+
- [JSON-Patch/RFC-6902](https://tools.ietf.org/html/rfc6902) - When patching deeply nested documents, it is more convenient to use protocol designed especially for this. Using this protocol is specified with `Content-Type: application/json-patch+json` HTTP Request header.
1211+
1212+
If using `If-Match` concurrency control as described in the [data control and integrity section](#data-integrity-and-concurrency-control), you could potentially choose to calculate the body of new object client side. Note that the response body for a successful operation can be omitted by supplying a HTTP request header: `Prefer: return=minimal`.
1213+
1214+
```sh
1215+
$ echo '[{"op": "add", "path":"/foo", "value": "bar"}]' | http PATCH :8080/users/ar6ej4mkj5lfl688d8lg If-Match:'"1234567890123456789012345678901234567890"' \
1216+
Content-Type: application/json-patch+json \
1217+
Prefer: return=minimal
1218+
HTTP/1.1 204 No Content
1219+
```
12091220
12101221
### DELETE
12111222
Used to delete single resource document given its `ID`, or via [Query](#quering).
@@ -1288,19 +1299,6 @@ When a validator implements this interface, the method is called with the field'
12881299
12891300
See [schema.IP](https://godoc.org/github.com/rs/rest-layer/schema#IP) validator for an implementation example.
12901301
1291-
## JSON-Patch
1292-
1293-
When patching deeply nested documents, it is more convenient to use protocol designed especially for this, instead of top level document field replacement as described in [RFC-5789](http://tools.ietf.org/html/rfc5789). For this purpose `rest-layer` implements [JSON-Patch/RFC-6902](https://tools.ietf.org/html/rfc6902). In addition JSON-Patch allows field deletion, which is not possible with the simple field replacement.
1294-
1295-
If using `If-Match` concurrency control as described in the [data control and integrity section](#data-integrity-and-concurrency-control), you could potentially choose to calculate the body of new object client side. Note that the response body for a successful operation can be omitted by supplying a HTTP request header: `Prefer: return=minimal`.
1296-
1297-
```sh
1298-
$ echo '[{"op": "add", "path":"/foo", "value": "bar"}]' | http PATCH :8080/users/ar6ej4mkj5lfl688d8lg If-Match:'"1234567890123456789012345678901234567890"' \
1299-
Content-Type: application/json-patch+json \
1300-
Prefer: return=minimal
1301-
HTTP/1.1 204 No Content
1302-
```
1303-
13041302
## Timeout and Request Cancellation
13051303
13061304
REST Layer respects [context](https://godoc.org/context) deadline from end to end. Timeout and request cancellation are thus handled through `context`. Since Go 1.8, context is cancelled automatically if the user closes the connection.

0 commit comments

Comments
 (0)