Skip to content

Commit 61021cf

Browse files
committed
Update README.md for v0.2.0
1 parent 6cf03b0 commit 61021cf

File tree

1 file changed

+110
-84
lines changed

1 file changed

+110
-84
lines changed

README.md

Lines changed: 110 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
REST APIs made easy.
44

5-
[![godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/rs/rest-layer) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/rs/rest-layer/master/LICENSE) [![build](https://img.shields.io/travis/rs/rest-layer.svg?style=flat)](https://travis-ci.org/rs/rest-layer) [![Go Report Card](https://goreportcard.com/badge/github.com/rs/rest-layer)](https://goreportcard.com/report/github.com/rs/rest-layer)
5+
[![godoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/rs/rest-layer) [![license](https://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/rs/rest-layer/master/LICENSE) [![build](https://img.shields.io/travis/rs/rest-layer.svg?style=flat)](https://travis-ci.org/rs/rest-layer) [![Go Report Card](https://goreportcard.com/badge/github.com/rs/rest-layer)](https://goreportcard.com/report/github.com/rs/rest-layer)
66

77
REST Layer is an API framework heavily inspired by the excellent [Python Eve](http://python-eve.org). It helps you create a comprehensive, customizable, and secure REST (graph) API on top of pluggable [backend storages](#storage-handlers) with no boiler plate code so you can focus on your business logic.
88

@@ -40,7 +40,17 @@ The REST Layer framework is composed of several sub-packages:
4040
- [Hooks](#hooks)
4141
- [Sub Resources](#sub-resources)
4242
- [Dependency](#dependency)
43-
- [Quering](#quering)
43+
- [HTTP Request Headers](#http-request-headers)
44+
- [Prefer](#prefer)
45+
- [HTTP Request Methods](#http-request-methods)
46+
- [OPTIONS](#options)
47+
- [HEAD](#head)
48+
- [GET](#get)
49+
- [POST](#post)
50+
- [PUT](#put)
51+
- [PATCH](#patch)
52+
- [DELETE](#delete)
53+
- [Querying](#querying)
4454
- [Filtering](#filtering)
4555
- [Sorting](#sorting)
4656
- [Field Selection](#field-selection)
@@ -52,16 +62,6 @@ The REST Layer framework is composed of several sub-packages:
5262
- [Authentication & Authorization](#authentication-and-authorization)
5363
- [Conditional Requests](#conditional-requests)
5464
- [Data Integrity & Concurrency Control](#data-integrity-and-concurrency-control)
55-
- [HTTP Headers Support](#http-headers-support)
56-
- [Prefer](#prefer)
57-
- [HTTP Methods](#http-methods)
58-
- [HEAD](#head)
59-
- [GET](#get)
60-
- [POST](#post)
61-
- [PUT](#put)
62-
- [PATCH](#patch)
63-
- [DELETE](#delete)
64-
- [OPTIONS](#options)
6565
- [Data Validation](#data-validation)
6666
- [Nullable Values](#nullable-values)
6767
- [Extensible Data Validation](#extensible-data-validation)
@@ -77,22 +77,26 @@ The REST Layer framework is composed of several sub-packages:
7777

7878
## Breaking Changes
7979

80-
Until version 1.0 of rest-layer, breaking changes may occur at any time if you rely on the latest master version.
80+
Until we reach a stable v1, there will be occasional breaking changes to the rest-layer APIs. Breaking changes will however not arrive at patch releases.
8181

82-
Below is an overview over recent breaking changes, starting from an arbitrary point with PR #151:
82+
## Breaking changes since v0.2.0
83+
84+
No breaking changes since v0.2.0.
85+
86+
## Breaking changes prior to v0.2.0
87+
88+
Below is an incomplete list of breaking changes included in v0.2.0:
8389

8490
- PR #151: `ValuesValidator FieldValidator` attribute in `schema.Dict` struct replaced by `Values Field`.
8591
- PR #179: `ValuesValidator FieldValidator` attribute in `schema.Array` struct replaced by `Values Field`.
86-
- PR #204:
92+
- PR #204:
8793
- Storage drivers need to accept pointer to `Expression` implementer in `query.Predicate`.
8894
- `filter` parameters in sub-query will be validated for type match.
8995
- `filter` parameters will be validated for type match only, instead of type & constrains.
9096
- PR #228: `Reference` projection fields will be validated against referenced resource schema.
9197
- PR #230: `Connection` projection fields will be validated against connected resource schema.
9298
- PR #241: Always call `OnUpdate` field hook on HTTP PUT for existing documents. Deleting a field with `Default` value set, will always be reset to its default value.
9399

94-
From the next release and onwards (0.2), this list will summarize breaking changes done to master since the last release.
95-
96100
## Features
97101

98102
- [x] Automatic handling of REST resource operations
@@ -145,16 +149,17 @@ As REST Layer is a simple `net/http` handler. You can use standard middleware to
145149
- [ ] Operations Log
146150
- [x] [Hystrix storage handler wrapper](https://github.com/rs/rest-layer-hystrix)
147151

148-
### Storage Handlers
152+
### Main Storage Handlers
149153

150154
- [x] [Memory](http://github.com/rs/rest-layer/tree/master/resource/testing/mem) (test only)
151155
- [x] [MongoDB](http://github.com/rs/rest-layer-mongo)
152-
- [x] [ElasticSearch](http://github.com/rs/rest-layer-es)
153-
- [x] [SQL](https://github.com/apuigsech/rest-layer-sql) (third party)
154-
- [x] [Google Datastore](https://github.com/ajcrowe/rest-layer-datastore) (third party)
155-
- [x] [Kubernetes ConfigMap](https://github.com/Segence/rest-layer-kubernetes-configmap) (third party)
156-
- [ ] Redis
157-
- [ ] Google BigTable
156+
157+
### Alternate Storage Handlers
158+
159+
- [ElasticSearch](http://github.com/rs/rest-layer-es) (no longer actively tested)
160+
- [SQL](https://github.com/apuigsech/rest-layer-sql) (third party)
161+
- [Google Datastore](https://github.com/ajcrowe/rest-layer-datastore) (third party)
162+
- [Kubernetes ConfigMap](https://github.com/Segence/rest-layer-kubernetes-configmap) (third party)
158163

159164
## Usage
160165

@@ -838,7 +843,78 @@ post = schema.Schema{
838843
}
839844
```
840845

841-
## Quering
846+
## HTTP Request Headers
847+
848+
### Prefer
849+
850+
Currently supported values are:
851+
852+
- [return=minimal](https://tools.ietf.org/html/rfc7240#section-4.2): When a request is successfully (HTTP Response Status of `200` or `201`), response body is not returned. For Response Status of `200 OK`, status becomes `204 No Content`. Can be used for e.g `PUT`, `POST` and `PATCH` methods, where returned body will be known by the client.
853+
- [return=no-content](https://msdn.microsoft.com/en-us/library/hh537533.aspx): same as `return=minimal`.
854+
855+
```sh
856+
$ echo '[{"op": "add", "path":"/foo", "value": "bar"}]' | http PATCH :8080/users/ar6ej4mkj5lfl688d8lg If-Match:'"1234567890123456789012345678901234567890"' \
857+
Content-Type: application/json-patch+json \
858+
Prefer: return=minimal
859+
HTTP/1.1 204 No Content
860+
```
861+
862+
### Content-Type
863+
864+
The Content-Type of the request body. Most HTTP methods only support `"aplication/json"` by default, but `PUT` requests also allow `"application/json-patch+json"`.
865+
866+
## HTTP Request Methods
867+
868+
Following HTTP Methods are currently supported by rest-layer.
869+
870+
### OPTIONS
871+
872+
Used to tell the client which HTTP Methods are supported for any given path.
873+
874+
### HEAD
875+
876+
The same as `GET`, except it includes only headers in the response.
877+
878+
### GET
879+
880+
Used to retrieve a (projected[#field-selection]) resource document by specifying it's `ID` in the path, or to retrieve a paginated view of documents matching a [query](#quering).
881+
882+
### POST
883+
884+
Used to create new resource document when the `ID` can be generated by the server. Field default values are set for omitted fields, and `OnCreate` field hooks are issued.
885+
886+
### PUT
887+
888+
Used to create or update a single resource document by specifying it's `ID` in the path. Field default values are set for omitted fields. If the document did not previously exist `OnCreate` field hooks are issued, otherwise `OnUpdate` field hooks are issued.
889+
890+
`If-Match` [concurrency protection](#data-integrity-and-concurrency-control) could be used if relevant.
891+
892+
### PATCH
893+
894+
Used to create or patch a single resource document by specifying it's `ID` in the path. `OnUpdate` field hooks are issued.
895+
896+
REST Layer supports two PATCH protocols, that can be specified via the `Content-Type` header.
897+
898+
- Simple filed replacement [RFC-5789](http://tools.ietf.org/html/rfc5789) - this protocol will update 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.
899+
900+
- [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.
901+
902+
`If-Match` [concurrency protection](#data-integrity-and-concurrency-control) could be used if relevant.
903+
904+
Example JSON Patch Request where we utilize concurrency control ask for the response body to be omitted:
905+
906+
```sh
907+
$ echo '[{"op": "add", "path":"/foo", "value": "bar"}]' | http PATCH :8080/users/ar6ej4mkj5lfl688d8lg If-Match:'"1234567890123456789012345678901234567890"' \
908+
Content-Type: application/json-patch+json \
909+
Prefer: return=minimal
910+
HTTP/1.1 204 No Content
911+
```
912+
913+
### DELETE
914+
915+
Used to delete single resource document given its `ID`, or multiple documents matching a [query](#quering).
916+
917+
## Querying
842918

843919
When supplying query parameters be sure to honor URL encoding scheme. If you need to include `+` sign, use `%2B`, etc.
844920

@@ -904,7 +980,7 @@ The flags are:
904980
|`i` |case-insensitive | false
905981
|`m` |multi-line mode: ^ and $ match begin/end line in addition to begin/end text| false
906982
|`s` |let . match \n | false
907-
|`U` |ungreedy: swap meaning of x\* and x\*?, x+ and x+?, etc | false
983+
|`U` |non-greedy: swap meaning of x\* and x\*?, x+ and x+?, etc | false
908984
909985
For example the following regular expression would match any document with a field `type` and its value `rest-layer`.
910986
@@ -919,7 +995,7 @@ The same example with flags:
919995
```
920996
921997
However, keep in mind that Storers have to support regular expression and depending on the implementation of the storage handler the accepted syntax may vary.
922-
An error of `ErrNotImplemented` will be returned for those storage backends which do not support the `$regex` operator.
998+
An error of `ErrNotImplemented` will be returned for those storage back-ends which do not support the `$regex` operator.
923999
9241000
The `$elemMatch` operator matches documents that contain an array field with at least one element that matches all the specified query criteria.
9251001
```go
@@ -934,14 +1010,18 @@ The `$elemMatch` operator matches documents that contain an array field with at
9341010
```
9351011
9361012
Matching documents that contain specific values within array objects can be done with `$elemMatch`:
1013+
9371014
```js
9381015
{telephones: {$elemMatch: {name: "John Snow", active: true}}}
9391016
```
1017+
9401018
The snippet above will return all documents, which `telephones` array field contains objects that have `name` **_AND_** `active` fields matching queried values.
9411019
> Note that documents returned may contain other objects in `telephones` that don't match the query above, but at least one object will do. Further filtering could be needed on the API client side.
9421020
9431021
#### *$elemMatch* Limitation
1022+
9441023
`$elemMatch` will work only for arrays of objects for now. Later it could be extended to work on plain arrays e.g:
1024+
9451025
```js
9461026
{numbers: {$elemMatch: {$gt: 20}}}
9471027
```
@@ -970,13 +1050,13 @@ Sorting of resource items is defined through the `sort` query-string parameter.
9701050
9711051
To use a resource field with the `sort` parameter, the field must be defined on the resource and the `Sortable` field property must be set to `true`. You may want to ensure the backend database has this field indexed when enabled.
9721052
973-
Here we sort the result by ascending quantity and descending date:
1053+
Here we sort the result by ascending quantity and descending create time:
9741054
9751055
/posts?sort=quantity,-created
9761056
9771057
### Field Selection
9781058
979-
REST APIs tend to grow over time. Resources get more and more fields to fulfill the needs for new features. But each time fields are added, all existing API clients automatically get the additional cost. This tend to lead to huge waste of bandwidth and added latency due to the transfer of unnecessary data. As a workaround, the `field` parameter can be used to minimize and customize the response body from requests with a `GET`, `PATCH` or `PUT` method on resource URLs.
1059+
REST APIs tend to grow over time. Resources get more and more fields to fulfill the needs for new features. But each time fields are added, all existing API clients automatically get the additional cost. This tend to lead to huge waste of bandwidth and added latency due to the transfer of unnecessary data. As a workaround, the `field` parameter can be used to minimize and customize the response body from requests with a `GET`, `POST`, `PUT` or `PATCH` method on resource URLs.
9801060
9811061
REST Layer provides a powerful fields selection (also named projection) system. If you provide the `fields` parameter with a list of fields for the resource you are interested in separated by commas, only those fields will be returned in the document:
9821062
@@ -1004,6 +1084,7 @@ $ http -b :8080/api/users/ar6eimekj5lfktka9mt0/posts fields=='meta{title,body}'
10041084
```
10051085
10061086
Also `all fields` expansion is supported:
1087+
10071088
```sh
10081089
$ http -b :8080/api/users/ar6eimekj5lfktka9mt0/posts fields=='*,user{*}'
10091090
[
@@ -1224,61 +1305,6 @@ This time the update operation was accepted and we got a new `ETag` for the upda
12241305
12251306
Concurrency control header `If-Match` can be used with all mutation methods on item URLs: `PATCH` (update), `PUT` (replace) and `DELETE` (delete).
12261307
1227-
## HTTP Headers Support
1228-
1229-
### Prefer
1230-
1231-
Currently supported values are:
1232-
- [return=minimal](https://tools.ietf.org/html/rfc7240#section-4.2) - When request is successfull (HTTP Response Status of `200` or `201`), response body is not returned. For Response Status of `200 OK`, status becomes `204 No Content`. Usefull for `PUT`, `POST` and `PATCH` methods, where returned body will be known by the client.
1233-
- [return-no-content](https://msdn.microsoft.com/en-us/library/hh537533.aspx) - same as `return=minimal`.
1234-
1235-
```sh
1236-
$ echo '[{"op": "add", "path":"/foo", "value": "bar"}]' | http PATCH :8080/users/ar6ej4mkj5lfl688d8lg If-Match:'"1234567890123456789012345678901234567890"' \
1237-
Content-Type: application/json-patch+json \
1238-
Prefer: return=minimal
1239-
HTTP/1.1 204 No Content
1240-
```
1241-
1242-
## HTTP Methods
1243-
1244-
Following HTTP Methods are supported currently.
1245-
1246-
### HEAD
1247-
The same as [GET](#get), except that it doesn't return any body.
1248-
1249-
### GET
1250-
Used to query a resource with its sub/embedded resources.
1251-
1252-
### POST
1253-
Used to create new resource document, where new `ID` is generated from the server.
1254-
1255-
### PUT
1256-
Used to create/update single resource document given its `ID`. On initial request, `onInsert` resource hook will be called. All subsequent `PUT` requests will call `onUpdate` resource hook.
1257-
1258-
Be aware when dealing with resource fields with `Default` set. If missing from payload or deleted, such fields will be reset to their `default value`.
1259-
1260-
### PATCH
1261-
Used to update/patch single resource document given its `ID`. REST Layer supports following update protocols:
1262-
1263-
- Simple filed replacement [RFC-5789](http://tools.ietf.org/html/rfc5789) - this protocol will update 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.
1264-
1265-
- [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.
1266-
1267-
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`.
1268-
1269-
```sh
1270-
$ echo '[{"op": "add", "path":"/foo", "value": "bar"}]' | http PATCH :8080/users/ar6ej4mkj5lfl688d8lg If-Match:'"1234567890123456789012345678901234567890"' \
1271-
Content-Type: application/json-patch+json \
1272-
Prefer: return=minimal
1273-
HTTP/1.1 204 No Content
1274-
```
1275-
1276-
### DELETE
1277-
Used to delete single resource document given its `ID`, or via [Query](#quering).
1278-
1279-
### OPTIONS
1280-
Used to tell the client, which HTTP Methods are supported on a given resource.
1281-
12821308
## Data Validation
12831309
12841310
Data validation is provided out-of-the-box. Your configuration includes a schema definition for every resource managed by the API. Data sent to the API to be inserted/updated will be validated against the schema, and a resource will only be updated if validation passes. See [Field Definition](#field-definition) section to know more about how to configure your validators.

0 commit comments

Comments
 (0)