Skip to content

Commit 710daea

Browse files
authored
Merge pull request #47 from thecodingmachine/45-remove-apisauce
Replace apisauce by axios
2 parents b1776a7 + 066a45b commit 710daea

File tree

4 files changed

+33
-35
lines changed

4 files changed

+33
-35
lines changed

App/Services/UserService.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import { create } from 'apisauce'
1+
import axios from 'axios'
22
import { Config } from 'App/Config'
3+
import { is, curryN, gte } from 'ramda'
4+
5+
const isWithin = curryN(3, (min, max, value) => {
6+
const isNumber = is(Number)
7+
return isNumber(min) && isNumber(max) && isNumber(value) && gte(value, min) && gte(max, value)
8+
})
9+
const in200s = isWithin(200, 299)
310

411
/**
512
* This is an example of a service that connects to a 3rd party API.
613
*
714
* Feel free to remove this example from your application.
815
*/
9-
10-
const userApiClient = create({
16+
const userApiClient = axios.create({
1117
/**
1218
* Import the config from the App/Config/index.js file
1319
*/
@@ -30,7 +36,7 @@ function fetchUser() {
3036
let number = Math.floor(Math.random() / 0.1) + 1
3137

3238
return userApiClient.get(number.toString()).then((response) => {
33-
if (response.ok) {
39+
if (in200s(response.status)) {
3440
return response.data
3541
}
3642

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The boilerplate contains:
4444
- [Redux Sagas](https://redux-saga.js.org) (v1.0.2) to separate side-effects and logic from state and UI logic
4545
- [React Navigation](https://reactnavigation.org/) (v3.6.0) with a [`NavigationService`](App/Services/NavigationService.js) to handle routing and navigation in the app, with a splash screen setup by default
4646
- [reduxsauce](https://github.com/infinitered/reduxsauce) (v1.0.1) to facilitate using Redux
47-
- [apisauce](https://github.com/infinitered/apisauce) (v1.0.2) to make [axios](https://github.com/axios/axios) even better
47+
- [axios](https://github.com/axios/axios) to make API calls (v0.19.0)
4848
- [prettier](https://prettier.io/) and [eslint](https://eslint.org/) preconfigured for React Native
4949

5050
The boilerplate includes an example (displaying fake user data) from UI components to the saga. The example is easy to remove so that it doesn't get in the way.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"rename": "react-native-rename"
1313
},
1414
"dependencies": {
15-
"apisauce": "^1.0.2",
15+
"axios": "^0.19.0",
1616
"prop-types": "^15.7.2",
1717
"react": "16.8.3",
1818
"react-native": "0.59.8",

yarn.lock

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,14 +1108,6 @@ anymatch@^2.0.0:
11081108
micromatch "^3.1.4"
11091109
normalize-path "^2.1.1"
11101110

1111-
apisauce@^1.0.2:
1112-
version "1.0.2"
1113-
resolved "https://registry.yarnpkg.com/apisauce/-/apisauce-1.0.2.tgz#3605dbf4f19896618a0199f2cb717546b8971a06"
1114-
integrity sha512-RwC0X4D20HH8t43J2mLNFv1ZNab+xTMcKyjRsajT0PbqiRXRjPfA9igBZ/f+2NaiIXHtyjLirqXY2SMLsUekTw==
1115-
dependencies:
1116-
axios "^0.18.0"
1117-
ramda "^0.25.0"
1118-
11191111
append-transform@^1.0.0:
11201112
version "1.0.0"
11211113
resolved "https://registry.yarnpkg.com/append-transform/-/append-transform-1.0.0.tgz#046a52ae582a228bd72f58acfbe2967c678759ab"
@@ -1290,13 +1282,13 @@ aws4@^1.8.0:
12901282
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
12911283
integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==
12921284

1293-
axios@^0.18.0:
1294-
version "0.18.0"
1295-
resolved "https://registry.yarnpkg.com/axios/-/axios-0.18.0.tgz#32d53e4851efdc0a11993b6cd000789d70c05102"
1296-
integrity sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=
1285+
axios@^0.19.0:
1286+
version "0.19.0"
1287+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0.tgz#8e09bff3d9122e133f7b8101c8fbdd00ed3d2ab8"
1288+
integrity sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==
12971289
dependencies:
1298-
follow-redirects "^1.3.0"
1299-
is-buffer "^1.1.5"
1290+
follow-redirects "1.5.10"
1291+
is-buffer "^2.0.2"
13001292

13011293
13021294
version "10.0.1"
@@ -1948,12 +1940,12 @@ [email protected], debug@^2.1.2, debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.
19481940
dependencies:
19491941
ms "2.0.0"
19501942

1951-
debug@^3.2.6:
1952-
version "3.2.6"
1953-
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
1954-
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
1943+
debug@=3.1.0:
1944+
version "3.1.0"
1945+
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
1946+
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
19551947
dependencies:
1956-
ms "^2.1.1"
1948+
ms "2.0.0"
19571949

19581950
debug@^4.0.1, debug@^4.1.0, debug@^4.1.1:
19591951
version "4.1.1"
@@ -2839,12 +2831,12 @@ flatted@^2.0.0:
28392831
resolved "https://registry.yarnpkg.com/flatted/-/flatted-2.0.0.tgz#55122b6536ea496b4b44893ee2608141d10d9916"
28402832
integrity sha512-R+H8IZclI8AAkSBRQJLVOsxwAoHd6WC40b4QTNWIjzAa6BXOBfQcM587MXDTVPeYaopFNWHUFLx7eNmHDSxMWg==
28412833

2842-
follow-redirects@^1.3.0:
2843-
version "1.7.0"
2844-
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.7.0.tgz#489ebc198dc0e7f64167bd23b03c4c19b5784c76"
2845-
integrity sha512-m/pZQy4Gj287eNy94nivy5wchN3Kp+Q5WgUPNy5lJSZ3sgkVKSYV/ZChMAQVIgx1SqfZ2zBZtPA2YlXIWxxJOQ==
2834+
follow-redirects@1.5.10:
2835+
version "1.5.10"
2836+
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
2837+
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
28462838
dependencies:
2847-
debug "^3.2.6"
2839+
debug "=3.1.0"
28482840

28492841
for-in@^1.0.1, for-in@^1.0.2:
28502842
version "1.0.2"
@@ -3351,6 +3343,11 @@ is-buffer@^1.1.5:
33513343
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
33523344
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==
33533345

3346+
is-buffer@^2.0.2:
3347+
version "2.0.3"
3348+
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-2.0.3.tgz#4ecf3fcf749cbd1e472689e109ac66261a25e725"
3349+
integrity sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==
3350+
33543351
is-callable@^1.1.4:
33553352
version "1.1.4"
33563353
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.4.tgz#1e1adf219e1eeb684d691f9d6a05ff0d30a24d75"
@@ -5652,11 +5649,6 @@ ramda@^0.24.1:
56525649
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.24.1.tgz#c3b7755197f35b8dc3502228262c4c91ddb6b857"
56535650
integrity sha1-w7d1UZfzW43DUCIoJixMkd22uFc=
56545651

5655-
ramda@^0.25.0:
5656-
version "0.25.0"
5657-
resolved "https://registry.yarnpkg.com/ramda/-/ramda-0.25.0.tgz#8fdf68231cffa90bc2f9460390a0cb74a29b29a9"
5658-
integrity sha512-GXpfrYVPwx3K7RQ6aYT8KPS8XViSXUVJT1ONhoKPE9VAleW42YE+U+8VEyGWt41EnEQW7gwecYJriTI0pKoecQ==
5659-
56605652
ramdasauce@^2.0.0:
56615653
version "2.1.3"
56625654
resolved "https://registry.yarnpkg.com/ramdasauce/-/ramdasauce-2.1.3.tgz#acb45ecc7e4fc4d6f39e19989b4a16dff383e9c2"

0 commit comments

Comments
 (0)