You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -69,7 +70,7 @@ redux-actions will automatically set ```action.error``` to true.
69
70
70
71
The following are **Verb Based Examples** so you can see how to use your actions
71
72
72
-
#####GET
73
+
### GET
73
74
```js
74
75
let getItems =createAPIAction('ITEMS', 'GET', '/items' );
75
76
getItems()
@@ -82,22 +83,27 @@ there is no need to pass a payload to your action, as its a `GET` request
82
83
-`ITEMS_GET_SUCCESS`
83
84
-`ITEMS_GET_FAILURE`
84
85
85
-
##### GET (single)
86
-
```js
87
-
let getSingleItem =createAPIAction('SINGLE_ITEM', 'GET', '/items' );
88
-
getSingleItem(15)
86
+
**Sample**
89
87
88
+
```json
89
+
{
90
+
type: 'ITEMS',
91
+
payload: {},
92
+
meta: {
93
+
api: true,
94
+
method: 'GET',
95
+
endpoint: '/items',
96
+
types: [
97
+
'ITEMS_GET_REQUEST',
98
+
'ITEMS_GET_SUCCESS',
99
+
'ITEMS_GET_FAILURE'
100
+
]
101
+
}
102
+
}
90
103
```
91
-
Here, we pass `15` as a parameter to the action, representing a case where we want only 1 item.
92
-
It's also important to note that we used a separate key, `SINGLE_ITEM`, to differentiate between
93
-
a single and All request.
94
104
95
-
*Auto Generated Action Types*
96
-
-`SINGLE_ITEM_GET_REQUEST`
97
-
-`SINGLE_ITEM_GET_SUCCESS`
98
-
-`SINGLE_ITEM_GET_FAILURE`
99
105
100
-
#####POST
106
+
### POST
101
107
102
108
```js
103
109
let createItem =createAPIAction('ITEMS', 'POST', '/items' );
@@ -111,7 +117,29 @@ Any data passed as the first parameter will be treated as the payload to be sent
111
117
-`ITEMS_POST_SUCCESS`
112
118
-`ITEMS_POST_FAILURE`
113
119
114
-
##### PUT
120
+
**Sample**
121
+
122
+
```json
123
+
{
124
+
type: 'ITEMS',
125
+
payload: {
126
+
name: "James Kusachi"
127
+
},
128
+
meta: {
129
+
api: true,
130
+
method: 'POST',
131
+
endpoint: '/sample',
132
+
types: [
133
+
'ITEMS_POST_REQUEST',
134
+
'ITEMS_POST_SUCCESS',
135
+
'ITEMS_POST_FAILURE'
136
+
]
137
+
}
138
+
}
139
+
```
140
+
141
+
142
+
### PUT
115
143
116
144
```js
117
145
let updateItem =createAPIAction('ITEMS', 'PUT', '/items' );
@@ -129,7 +157,28 @@ In this case, we are updating primary item `15` with a new object
129
157
-`ITEMS_PUT_SUCCESS`
130
158
-`ITEMS_PUT_FAILURE`
131
159
132
-
##### DELETE
160
+
**Sample**
161
+
162
+
```json
163
+
{
164
+
type: 'ITEMS',
165
+
payload: {
166
+
name: 'james'
167
+
},
168
+
meta: {
169
+
api: true,
170
+
method: 'PUT',
171
+
endpoint: '/sample/10',
172
+
types: [
173
+
'ITEMS_PUT_REQUEST',
174
+
'ITEMS_PUT_SUCCESS',
175
+
'ITEMS_PUT_FAILURE'
176
+
]
177
+
}
178
+
}
179
+
```
180
+
181
+
### DELETE
133
182
```js
134
183
let deleteItem =createAPIAction('ITEMS', 'DELETE', '/items' );
135
184
updateItem(15);
@@ -143,3 +192,83 @@ No need to pass in any payload data, as that would get dropped anyways because o
143
192
-`ITEMS_DELETE_SUCCESS`
144
193
-`ITEMS_DELETE_FAILURE`
145
194
195
+
**Sample**
196
+
197
+
```json
198
+
{
199
+
type: 'ITEMS',
200
+
payload: {},
201
+
meta: {
202
+
api: true,
203
+
method: 'DELETE',
204
+
endpoint: '/sample/5',
205
+
types: [
206
+
'ITEMS_DELETE_REQUEST',
207
+
'ITEMS_DELETE_SUCCESS',
208
+
'ITEMS_DELETE_FAILURE'
209
+
]
210
+
}
211
+
}
212
+
```
213
+
214
+
215
+
# Advanced (`{function} endpoint`)
216
+
217
+
In cases where you need to customize the endpoint with more granularity, you can pass a `function` as the `endpoint` instead of a string. This gives you access to the payload so you can create dynamic endpoints based on the payload.
218
+
219
+
NOTE: When using the Advanced method, you only need to send a payload across. In the Simple version, parameter order is important (IE: for PUTs, first parameter is ID, second is payload, for POST the parameter is the payload).
220
+
221
+
For the advanced version, you only need to send the payload, and your endpoint will return dynamically based on your function.
0 commit comments