Skip to content

Commit 413d791

Browse files
authored
Merge pull request #5 from PilotConway/feature/crud
Added CI
2 parents 66981b1 + e750c14 commit 413d791

12 files changed

+178
-10
lines changed

.eslintrc.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
parser: 'babel-eslint',
3+
env: {
4+
browser: true,
5+
es6: true,
6+
jest: true,
7+
},
8+
extends: 'eslint:recommended',
9+
globals: {
10+
Atomics: 'readonly',
11+
SharedArrayBuffer: 'readonly',
12+
},
13+
parserOptions: {
14+
ecmaFeatures: {
15+
jsx: true,
16+
},
17+
ecmaVersion: 2018,
18+
sourceType: 'module',
19+
},
20+
plugins: ['react'],
21+
rules: {},
22+
};

.github/main.workflow

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ workflow "Link on Push" {
44
}
55

66
action "eslint" {
7-
uses = "gimenete/eslint-action@1.0"
7+
uses = "stefanoeb/eslint-action@master"
88
}

.prettierrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"printWidth": 80,
2+
"printWidth": 100,
33
"tabWidth": 2,
44
"useTabs": false,
55
"semi": true,
@@ -8,4 +8,4 @@
88
"bracketSpacing": true,
99
"jsxBracketSameLine": false,
1010
"fluid": false
11-
}
11+
}

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: node_js
2+
node_js:
3+
- '10'
4+
after_success:
5+
- yarn codecov

README.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Build Status](https://travis-ci.com/PilotConway/rxjs-api-client-prototype.svg?branch=master)](https://travis-ci.com/PilotConway/rxjs-api-client-prototype) [![codecov](https://codecov.io/gh/PilotConway/rxjs-api-client-prototype/branch/master/graph/badge.svg)](https://codecov.io/gh/PilotConway/rxjs-api-client-prototype)
2+
13
# rxjs-api-client-prototype
24

35
This is a prototype project to feel out ways I can use RxJS to replace the apps current server.js
@@ -24,7 +26,7 @@ import ClientProvider from 'src/ClientProvider';
2426
function Root() {
2527
const client = createClient('https://localhost:3000/api/v1');
2628
return (
27-
<ClientProvider client={client}>
29+
<ClientProvider value={client}>
2830
<App />
2931
</ClientProvider>
3032
);
@@ -42,6 +44,8 @@ the url as provided to make the call.
4244
</Request>
4345
```
4446

47+
By default, if you do not provide a client using the `ClientProvider` and use a realtive endpoint in `Request` or `useEndpointData` then a default client using `window.location.origin` as the base url will be used.
48+
4549
### Render Prop Method
4650

4751
The `<Request>` component provides a render prop method of performing a GET Request to retrieve
@@ -71,7 +75,7 @@ import React from 'react';
7175
import useEndpointData from 'src/useEndpointData`;
7276
7377
export default function MyComponent() {
74-
const [ data, loading, error, links, client ] = useEndpointHooks('/users');
78+
const [ data, loading, error, links, client ] = useEndpointHooks('/users', { params: { per_page: 5 }});
7579
return (
7680
... your component jsx
7781
)
@@ -82,12 +86,51 @@ See [`useEndpointData`](#useEndpointData) for details on the hook parameters and
8286
8387
## API
8488
85-
### `Client`
89+
### `client`
90+
91+
This is base object that is used to make requests to the server. It is recommended that you do not create this object but instead use `createClient` to create a new client.
92+
93+
Both `Request` and `useEndpointData` will also provide the client object so you can use it to make other requests to the server such as a put/post/delete.
94+
95+
#### Functions
96+
97+
The `client` object contains 4 functions that can be used to communicate with the server.
98+
99+
- get
100+
- put
101+
- post
102+
- delete
103+
104+
##### get()
105+
106+
Performs a get request to the server.
86107
87108
### `createClient`
88109
110+
This function creates a new client. It's preferred over using `client` itself as you can set the base URL and headers using `createClient` where with `client` you will have to pass full URLs to every request.
111+
89112
### `<ClientProvider>`
90113

114+
The ClientProvider allows for a client to be set as the default client for all requests in the component tree below the provider. You can use [`createClient`](#createClient) to create a client with a specific base url then use relative endpoints in all `Request` or `useEndpointData` calls to get information from the server.
115+
116+
In addition to being able to set the base url, you can also set headers and other information for every request to use.
117+
118+
```js
119+
...
120+
import { createClient } from 'src/client';
121+
import ClientProvider from 'src/ClientProvider';
122+
...
123+
124+
function Root() {
125+
const client = createClient('https://localhost:3000/api/v1');
126+
return (
127+
<ClientProvider value={client}>
128+
<App />
129+
</ClientProvider>
130+
);
131+
}
132+
```
133+
91134
### `useEndpointData`
92135

93136
This is a hook to perform a GET request to retrieve data.
@@ -145,6 +188,8 @@ The render function is called with a single parameter object that has the follow
145188

146189
### Request Error
147190

191+
TODO: define request error and ensure all errors follow this format.
192+
148193
### Pagination
149194

150195
When an endpoint supports Pagination, the response will contain a link object. This is passed

codecov.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
codecov:
2+
notify:
3+
require_ci_to_pass: yes
4+
5+
coverage:
6+
precision: 2
7+
round: down
8+
range: '50...90'
9+
status:
10+
patch: off
11+
project:
12+
default:
13+
target: auto
14+
threshold: null
15+
base: pr
16+
ignore:
17+
- '**/*.spec.*'
18+
- '**/*.stories.*'
19+
- 'src/components/**/*'
20+
21+
parsers:
22+
gcov:
23+
branch_detection:
24+
conditional: yes
25+
loop: yes
26+
method: no
27+
macro: no
28+
29+
comment:
30+
layout: 'header, diff'
31+
behavior: default
32+
require_changes: no

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"rxjs": "6.5.2"
1616
},
1717
"devDependencies": {
18+
"codecov": "^3.5.0",
1819
"typescript": "3.3.3"
1920
},
2021
"scripts": {

src/client/client.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import client from './client';
2+
// Require get request import for mocks to work
3+
// eslint-disable-next-line no-unused-vars
24
import getRequest from './getRequest';
35

46
// SEE __mocks__/getRequest for which endpoint paths result in what types of

src/client/createClient.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import createClient from './createClient';
2+
// Require get request import for mocks to work
3+
// eslint-disable-next-line no-unused-vars
24
import getRequest from './getRequest';
35

46
// SEE __mocks__/getRequest for which endpoint paths result in what types of

src/client/getRequest.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@ const getRequest = path =>
88
if (response === null) {
99
return throwError('API Timed out', response);
1010
}
11-
console.log('api response: ', response);
1211
return response;
1312
}),
1413
catchError(error => {
15-
console.log(error);
16-
console.error('api error: ', error.response);
1714
return of(error);
1815
}),
1916
);
File renamed without changes.

yarn.lock

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,13 @@ address@^1.0.1:
16441644
resolved "https://registry.yarnpkg.com/address/-/address-1.1.0.tgz#ef8e047847fcd2c5b6f50c16965f924fd99fe709"
16451645
integrity sha512-4diPfzWbLEIElVG4AnqP+00SULlPzNuyJFNnmMrLgyaxG6tZXJ1sn7mjBu4fHrJE+Yp/jgylOweJn2xsLMFggQ==
16461646

1647+
agent-base@^4.1.0:
1648+
version "4.3.0"
1649+
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.3.0.tgz#8165f01c436009bccad0b1d122f05ed770efc6ee"
1650+
integrity sha512-salcGninV0nPrwpGNn4VTXBb1SOuXQBiqbrNXoeizJsHrsL6ERFM2Ne3JUSBWRE6aeNJI2ROP/WEEIDUiDe3cg==
1651+
dependencies:
1652+
es6-promisify "^5.0.0"
1653+
16471654
ajv-errors@^1.0.0:
16481655
version "1.0.1"
16491656
resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-1.0.1.tgz#f35986aceb91afadec4102fbd85014950cefa64d"
@@ -1739,6 +1746,11 @@ argparse@^1.0.7:
17391746
dependencies:
17401747
sprintf-js "~1.0.2"
17411748

1749+
argv@^0.0.2:
1750+
version "0.0.2"
1751+
resolved "https://registry.yarnpkg.com/argv/-/argv-0.0.2.tgz#ecbd16f8949b157183711b1bda334f37840185ab"
1752+
integrity sha1-7L0W+JSbFXGDcRsb2jNPN4QBhas=
1753+
17421754
aria-query@^3.0.0:
17431755
version "3.0.0"
17441756
resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-3.0.0.tgz#65b3fcc1ca1155a8c9ae64d6eee297f15d5133cc"
@@ -2605,6 +2617,17 @@ code-point-at@^1.0.0:
26052617
resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77"
26062618
integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=
26072619

2620+
codecov@^3.5.0:
2621+
version "3.5.0"
2622+
resolved "https://registry.yarnpkg.com/codecov/-/codecov-3.5.0.tgz#3d0748932f9cb41e1ad7f21fa346ef1b2b1bed47"
2623+
integrity sha512-/OsWOfIHaQIr7aeZ4pY0UC1PZT6kimoKFOFYFNb6wxo3iw12nRrh+mNGH72rnXxNsq6SGfesVPizm/6Q3XqcFQ==
2624+
dependencies:
2625+
argv "^0.0.2"
2626+
ignore-walk "^3.0.1"
2627+
js-yaml "^3.13.1"
2628+
teeny-request "^3.11.3"
2629+
urlgrey "^0.4.4"
2630+
26082631
collection-visit@^1.0.0:
26092632
version "1.0.0"
26102633
resolved "https://registry.yarnpkg.com/collection-visit/-/collection-visit-1.0.0.tgz#4bc0373c164bc3291b4d368c829cf1a80a59dca0"
@@ -3178,7 +3201,7 @@ [email protected], debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.8, debug@^2.6.
31783201
dependencies:
31793202
ms "2.0.0"
31803203

3181-
debug@^3.2.5, debug@^3.2.6:
3204+
debug@^3.1.0, debug@^3.2.5, debug@^3.2.6:
31823205
version "3.2.6"
31833206
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
31843207
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
@@ -3589,6 +3612,18 @@ es-to-primitive@^1.2.0:
35893612
is-date-object "^1.0.1"
35903613
is-symbol "^1.0.2"
35913614

3615+
es6-promise@^4.0.3:
3616+
version "4.2.8"
3617+
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a"
3618+
integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==
3619+
3620+
es6-promisify@^5.0.0:
3621+
version "5.0.0"
3622+
resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-5.0.0.tgz#5109d62f3e56ea967c4b63505aef08291c8a5203"
3623+
integrity sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=
3624+
dependencies:
3625+
es6-promise "^4.0.3"
3626+
35923627
escape-html@~1.0.3:
35933628
version "1.0.3"
35943629
resolved "https://registry.yarnpkg.com/escape-html/-/escape-html-1.0.3.tgz#0258eae4d3d0c0974de1c169188ef0051d1d1988"
@@ -4731,6 +4766,14 @@ https-browserify@^1.0.0:
47314766
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
47324767
integrity sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=
47334768

4769+
https-proxy-agent@^2.2.1:
4770+
version "2.2.1"
4771+
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz#51552970fa04d723e04c56d04178c3f92592bbc0"
4772+
integrity sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==
4773+
dependencies:
4774+
agent-base "^4.1.0"
4775+
debug "^3.1.0"
4776+
47344777
hyphenate-style-name@^1.0.3:
47354778
version "1.0.3"
47364779
resolved "https://registry.yarnpkg.com/hyphenate-style-name/-/hyphenate-style-name-1.0.3.tgz#097bb7fa0b8f1a9cf0bd5c734cf95899981a9b48"
@@ -6514,6 +6557,11 @@ no-case@^2.2.0:
65146557
dependencies:
65156558
lower-case "^1.1.1"
65166559

6560+
node-fetch@^2.2.0:
6561+
version "2.6.0"
6562+
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd"
6563+
integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==
6564+
65176565
65186566
version "0.7.5"
65196567
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.7.5.tgz#6c152c345ce11c52f465c2abd957e8639cd674df"
@@ -9307,6 +9355,15 @@ tar@^4:
93079355
safe-buffer "^5.1.2"
93089356
yallist "^3.0.3"
93099357

9358+
teeny-request@^3.11.3:
9359+
version "3.11.3"
9360+
resolved "https://registry.yarnpkg.com/teeny-request/-/teeny-request-3.11.3.tgz#335c629f7645e5d6599362df2f3230c4cbc23a55"
9361+
integrity sha512-CKncqSF7sH6p4rzCgkb/z/Pcos5efl0DmolzvlqRQUNcpRIruOhY9+T1FsIlyEbfWd7MsFpodROOwHYh2BaXzw==
9362+
dependencies:
9363+
https-proxy-agent "^2.2.1"
9364+
node-fetch "^2.2.0"
9365+
uuid "^3.3.2"
9366+
93109367
93119368
version "1.2.3"
93129369
resolved "https://registry.yarnpkg.com/terser-webpack-plugin/-/terser-webpack-plugin-1.2.3.tgz#3f98bc902fac3e5d0de730869f50668561262ec8"
@@ -9723,6 +9780,11 @@ url@^0.11.0:
97239780
punycode "1.3.2"
97249781
querystring "0.2.0"
97259782

9783+
urlgrey@^0.4.4:
9784+
version "0.4.4"
9785+
resolved "https://registry.yarnpkg.com/urlgrey/-/urlgrey-0.4.4.tgz#892fe95960805e85519f1cd4389f2cb4cbb7652f"
9786+
integrity sha1-iS/pWWCAXoVRnxzUOJ8stMu3ZS8=
9787+
97269788
use@^3.1.0:
97279789
version "3.1.1"
97289790
resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f"

0 commit comments

Comments
 (0)