From 642609adf8f95d177a3a40066836ad7b9f2f8468 Mon Sep 17 00:00:00 2001 From: Joe Bordes Date: Wed, 6 May 2020 02:13:18 +0200 Subject: [PATCH] doc(DataProvider) minor syntax changes --- docs/DataProviders.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/DataProviders.md b/docs/DataProviders.md index 378cf6c9a64..6d2bd1128b5 100644 --- a/docs/DataProviders.md +++ b/docs/DataProviders.md @@ -15,7 +15,7 @@ dataProvider }); ``` -It's the Data Provider's job to turns these method calls into HTTP requests, and transform the HTTP responses to the data format expected by react-admin. In technical terms, a Data Provider is an *adapter* for an API. +It's the Data Provider's job to turn these method calls into HTTP requests, and transform the HTTP responses to the data format expected by react-admin. In technical terms, a Data Provider is an *adapter* for an API. And to inject a Data Provider in a react-admin application, pass it as the `dataProvider` prop of the `` component, as follows: @@ -202,7 +202,7 @@ Now all the requests to the REST API will contain the `Authorization: SRTRDFVESG ## Extending a Data Provider (Example of File Upload) -As Data Providers are just objects, you can extend them with custom logic for a given method, or for a given resource. +As Data Providers are just objects, you can extend them with custom logic for a given method, or a given resource. For instance, the following Data Provider extends the `ra-data-simple-rest` provider, and adds image upload support for the `update('posts')` call (react-admin offers an `` component that allows image upload). @@ -274,7 +274,7 @@ Using this technique, you can also combine two Data Providers for two backends i ## Writing Your Own Data Provider -APIs are so diverse that quite often, none of the available Data Providers suit you API. In such cases, you'll have to write your own Data Provider. Don't worry, it usually takes only a couple hours. +APIs are so diverse that quite often, none of the available Data Providers suit you API. In such cases, you'll have to write your own Data Provider. Don't worry, it usually takes only a couple of hours. The methods of a Data Provider receive a request, and return a promise for a response. Both the request and the response format are standardized. @@ -644,7 +644,7 @@ export default { When the API backend returns an error, the Data Provider should return a rejected Promise containing an `Error` object. This object should contain a `status` property with the HTTP response code (404, 500, etc.). React-admin inspects this error code, and uses it for [authentication](./Authentication.md) (in case of 401 or 403 errors). Besides, react-admin displays the error `message` on screen in a temporary notification. -If you use `fetchJson`, you don't need to do anything: HTTP errors are automaticlly decorated as expected by react-admin. +If you use `fetchJson`, you don't need to do anything: HTTP errors are automatically decorated as expected by react-admin. If you use another HTTP client, make sure you return a rejected Promise. You can use the `HttpError` class to throw an error with status in one line: