Skip to content

Commit 331d8d4

Browse files
committed
doc(README): fix typo and sentences, add roadmap
1 parent 7805270 commit 331d8d4

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

README.md

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ Simple, customizable, offline-first API wrapper for react-native.
44

55
Easily write offline-first react-native applications with your own REST API. This module supports every major features for network requests : middlewares, fine-grained control over caching logic, custom caching driver...
66

7+
## Table of contents
8+
79
- [react-native-offline-api](#react-native-offline-api)
10+
- [Table of contents](#table-of-contents)
811
- [Installation](#installation)
912
- [How to use](#how-to-use)
1013
- [Setting up your global API options](#setting-up-your-global-api-options)
@@ -18,6 +21,7 @@ Easily write offline-first react-native applications with your own REST API. Thi
1821
- [Middlewares](#middlewares)
1922
- [Using your own driver for caching](#using-your-own-driver-for-caching)
2023
- [Types](#types)
24+
- [Roadmap](#roadmap)
2125

2226
## Installation
2327

@@ -118,7 +122,7 @@ export default class demo extends Component {
118122
}
119123
```
120124

121-
In this short example, we're firing a `GET` request on the path `http://staging.myapi.tld/api/v2/documents/:xSfdk21`. If you don't understand how this path is constructed, see [path and query parameters](#path-and-query-parameters).
125+
In this short example, we're firing a `GET` request on the path `http://staging.myapi.tld/api/v2/documents/xSfdk21`. If you don't understand how this path is constructed, see [path and query parameters](#path-and-query-parameters).
122126

123127
A couple of notes :
124128

@@ -130,7 +134,7 @@ A couple of notes :
130134
Name | Description | Parameters | Return value
131135
------ | ------ | ------ | ------
132136
`fetch` | Fires a network request to one of your service with additional options, see [fetch options](#fetch-options) | `service: string, options?: IFetchOptions` | `Promise<any>`
133-
`fetchHeaders` | Just like `fetch` but only returns HTTP headers of the reponse | `service: string, options?: IFetchOptions` | `Promise<any>`
137+
`fetchHeaders` | Just like `fetch` but only returns the HTTP headers of the reponse | `service: string, options?: IFetchOptions` | `Promise<any>`
134138
`clearCache` | Clears all the cache, or just the one of a specific service | `service?: string` | `Promise<void>`
135139
`setOptions` | Sets or update the API options of the wrapper | `options: IAPIOptions` | `void`
136140
`setServices` | Sets or update your services definitions | `services: IAPIServices` | `void`
@@ -144,12 +148,12 @@ Key | Type | Description | Example
144148
------ | ------ | ------ | ------
145149
`domains` | `{ default: string, [key: string]: string }` | **Required**, full URL to your domains | `domains: {default: 'http://myapi.tld', staging: 'http://staging.myapi.tld' },`
146150
`prefixes` | `{ default: string, [key: string]: string }` | **Required**, prefixes your API uses, `default` is required, leave it blank if you don't have any | `{ default: '/api/v1', apiV2: '/api/v2' }`
147-
`middlewares` | Optional array of `APIMiddleware`, see [middlewares](#middlewares) | `[authFunc, trackFunc]`
151+
`middlewares` | `APIMiddleware[]` | Optionnal middlewares, see [middlewares](#middlewares) | `[authFunc, trackFunc]`
148152
`debugAPI` | `boolean` | Optional, enables debugging mode, printing what's the wrapper doing
149153
`printNetworkRequests` | `boolean` | Optional, prints all your network requests
150154
`disableCache` | `boolean` | Optional, completely disables caching (overriden by service definitions & `fetch`'s `option` parameter)
151155
`cacheExpiration` | `number` | Optional default expiration of cached data in ms (overriden by service definitions & `fetch`'s `option` parameter)
152-
`offlineDriver` | `IAPIDriver` | Optional, See [use your own driver for caching](#use-your-own-driver-for-caching)
156+
`offlineDriver` | `IAPIDriver` | Optional, see [use your own driver for caching](#use-your-own-driver-for-caching)
153157

154158
## Services options
155159

@@ -159,28 +163,28 @@ Key | Type | Description | Example
159163
------ | ------ | ------ | ------
160164
`path` | `string` | Required path to your endpoint, see [path and query parameters](#path-and-query-parameters) | `article/:articleId`
161165
`expiration` | `number` | Optional time in ms before this service's cached data becomes stale, defaults to 5 minutes
162-
`method` | HTTP Methods | Optional HTTP method of your request, defaults to `GET`
166+
`method` | `'GET' | 'POST' | 'OPTIONS'...` | Optional HTTP method of your request, defaults to `GET`
163167
`domain` | `string` | Optional specific domain to use for this service, provide the key you set in your `domains` API option
164168
`prefix` | `string` | Optional specific prefix to use for this service, provide the key you set in your `prefixes` API option
165-
`middlewares` | `APIMiddleware[]` | Optional array of middlewares that override the ones set globally in your `middlewares` API option
166-
`disableCache` | `boolean` | Optional, disables the cache for this service that override your API option
169+
`middlewares` | `APIMiddleware[]` | Optional array of middlewares that override the ones set globally in your `middlewares` API option, , see [middlewares](#middlewares)
170+
`disableCache` | `boolean` | Optional, disables the cache for this service (override your [API's global options](#api-options))
167171

168172
## Fetch options
169173

170-
The `options` parameter of the `fetch` methods overrides the configuration you set globally in your API options, and the one you set for your endpoints. This is a good way of making very specific calls without having to declare another service for a single use for instance.
174+
The `options` parameter of the `fetch` and `fetchHeaders` method overrides the configuration you set globally in your API options, and the one you set for your services definitions. For instance, this is a good way of making very specific calls without having to declare another service just to tweak a single option.
175+
176+
Important notes :
171177

172-
All of these are optional.
178+
* All of these are optional.
179+
* All the keys of [services options](#services-options) can be overriden here ! You could disable caching just for a single call for example, but still having it enabled in your service's definition.
173180

174181
Key | Type | Description | Example
175182
------ | ------ | ------ | ------
176183
`pathParameters` | `{ [key: string]: string }` | Parameters to replace in your path, see [path and query parameters](#path-and-query-parameters) | `{ documentId: 'xSfdk21' }`
177184
`queryParameters` | `{ [key: string]: string }` | Query parameters that will be appended to your service's path, , see [path and query parameters](#path-and-query-parameters) | `{ refresh: true, orderBy: 'date' }`
178185
`headers` | `{ [key: string]: string }` | HTTP headers you need to pass in your request
179-
`middlewares` | `APIMiddleware[]` | Optional array of middlewares that override the ones set globally in your `middlewares` API option and in your service's definition
180-
`fetchOptions` | `any` | Optional, any value passed here will be merged into the options of react-native's `fetch method` so you'll be able to configure anything not provided by the wrapper itself
181-
182-
183-
**All the keys of [service options](#service-options) can be overriden here !** You could disable caching just for a single call for example, but still having it enabled in your service's definition.
186+
`middlewares` | `APIMiddleware[]` | Optional array of middlewares that override the ones set globally in your `middlewares` API option and in your service's definition, , see [middlewares](#middlewares)
187+
`fetchOptions` | `any` | Optional, any value passed here will be merged into the options of react-native's `fetch` method so you'll be able to configure anything not provided by the wrapper itself
184188

185189
## Path and query parameters
186190

@@ -196,7 +200,7 @@ Just like for the other request options, **you can provide middlewares at the gl
196200

197201
You must provide an **array of promises**, like so : `(serviceDefinition: IAPIService, options: IFetchOptions) => any;`, please [take a look at the types](#types) to know more. You don't necessarily need to write asynchronous code in them, but they all must be promises.
198202

199-
Anything you will resolved in those promises will be merged into your request's options !
203+
Anything you will resolve in those promises will be merged into your request's options !
200204

201205
Here's a barebone example :
202206

@@ -207,6 +211,7 @@ const API_OPTIONS = {
207211
};
208212

209213
async function exampleMiddleware (serviceDefinition, serviceOptions) {
214+
// This will be printed everytime you call a service
210215
console.log('You just fired a request for the path ' + serviceDefinition.path);
211216
}
212217
```
@@ -261,4 +266,12 @@ Your custom driver must implement these 3 methods that are promises.
261266

262267
Every API interfaces [can be seen here](src/interfaces.ts) so you don't need to poke around the parameters in your console to be aware of what's available to you :)
263268

264-
These are Typescript defintions, so they should be displayed in your editor/IDE if it supports it.
269+
These are Typescript defintions, so they should be displayed in your editor/IDE if it supports it.
270+
271+
## Roadmap
272+
273+
Pull requests are more than welcome for these items, or for any feature that might be missing.
274+
275+
- [ ] Write a demo
276+
- [ ] Thoroughly test custom caching drivers, maybe provide one (realm or sqlite)
277+
- [ ] Add automated testing

0 commit comments

Comments
 (0)