@@ -10,7 +10,7 @@ This package helps you quickly to build requests for REST API. Move your logic a
10
10
classes. Keep your code clean and elegant.
11
11
12
12
Wouldn't it be great if you could just use your back end to validate forms on the front end? This package provides a
13
- ` BaseProxy ` class that does exactly that. It can post itself to a configured endpoint and manage errors. The class is
13
+ ` BaseService ` class that does exactly that. It can post itself to a configured endpoint and manage errors. The class is
14
14
meant to be used with a Laravel back end, and it doesn't limit that you need only to work with laravel, Ruby on Rail,
15
15
NodeJs, ExpressJs, or any other languages.
16
16
@@ -127,18 +127,18 @@ It will create `$errors` object inside components.
127
127
128
128
1.Create ** proxies** folder or your prefer folder name for this
129
129
130
- ` ~/proxies/NewsProxy .js `
130
+ ` ~/proxies/NewsService .js `
131
131
132
132
``` js
133
- import { BaseProxy } from ' vue-axios-http'
133
+ import { BaseService } from ' vue-axios-http'
134
134
135
- class NewsProxy extends BaseProxy {
135
+ class NewsService extends BaseService {
136
136
constructor (parameters = {}) {
137
137
super (' news' , parameters)
138
138
}
139
139
}
140
140
141
- export default NewsProxy
141
+ export default NewsService
142
142
```
143
143
144
144
2.Store
@@ -157,19 +157,19 @@ actions.js
157
157
158
158
``` js
159
159
import { ALL } from ' ./mutation-types'
160
- import { NewsProxy } from ' ~/proxies'
160
+ import { NewsService } from ' ~/proxies'
161
161
import { BaseTransformer , PaginationTransformer } from ' vue-axios-http'
162
162
import { pagination , notify } from ' ~/utils'
163
163
164
- const proxy = new NewsProxy ()
164
+ const service = new NewsService ()
165
165
166
166
const all = async ({ commit, dispatch }, payload = {}) => {
167
167
const { fn } = payload
168
168
if (typeof fn === ' function' ) {
169
- await fn (proxy )
169
+ await fn (service )
170
170
}
171
171
try {
172
- const { data , meta } = await proxy .all ()
172
+ const { data , meta } = await service .all ()
173
173
const all = {
174
174
items: BaseTransformer .fetchCollection (data),
175
175
pagination: PaginationTransformer .fetch (meta),
@@ -247,8 +247,8 @@ export default {
247
247
async asyncData ({ app, store }) {
248
248
const { id = null } = app .$auth .user
249
249
await store .dispatch (' news/all' , {
250
- fn : (proxy ) => {
251
- proxy
250
+ fn : (service ) => {
251
+ service
252
252
.setParameters ({
253
253
userId: id,
254
254
include: [' categories' ],
@@ -267,8 +267,8 @@ export default {
267
267
mounted () {
268
268
const { id = null } = this .$auth .user
269
269
this .$store .dispatch (' news/all' , {
270
- fn : (proxy ) => {
271
- proxy
270
+ fn : (service ) => {
271
+ service
272
272
.setParameters ({
273
273
userId: id,
274
274
include: [' categories' ],
@@ -282,7 +282,7 @@ export default {
282
282
283
283
You can set or remove any parameters you like.
284
284
285
- ## Proxy 's methods are available
285
+ ## Service 's methods are available
286
286
287
287
| Method | Description |
288
288
| ----------------------------------------------- | --------------------------- |
@@ -301,7 +301,7 @@ Set parameters with key/value.
301
301
#### Example
302
302
303
303
``` js
304
- const proxy = new ExampleProxy ()
304
+ const service = new ExampleService ()
305
305
const parameters = {
306
306
search: {
307
307
first_name: ' Sek' ,
@@ -317,7 +317,7 @@ const parameters = {
317
317
},
318
318
category_id: 6 ,
319
319
}
320
- const { data } = proxy .setParameters (parameters).all ()
320
+ const { data } = service .setParameters (parameters).all ()
321
321
this .data = data
322
322
```
323
323
@@ -334,8 +334,8 @@ if setParameter that value is empty or null it will remove that param for query
334
334
#### Example 1
335
335
336
336
``` js
337
- const proxy = new ExampleProxy ()
338
- const { data } = await proxy .setParameter (' page' , 1 ).all ()
337
+ const service = new ExampleService ()
338
+ const { data } = await service .setParameter (' page' , 1 ).all ()
339
339
this .data = data
340
340
```
341
341
@@ -350,9 +350,9 @@ Expected will be:
350
350
#### Example 2
351
351
352
352
``` js
353
- const proxy = new ExampleProxy ()
353
+ const service = new ExampleService ()
354
354
const queryString = ' limit=10&page=1&search[name]=hello'
355
- const { data } = await proxy .setParameter (queryString).all ()
355
+ const { data } = await service .setParameter (queryString).all ()
356
356
this .data = data
357
357
```
358
358
@@ -370,20 +370,20 @@ Expected will be:
370
370
371
371
Be sure to use only once in ` mounted() ` or ` asyncData() ` and ` asyncData() ` is only available in ` NuxtJs `
372
372
373
- ## Use proxy in components
373
+ ## Use service in components
374
374
375
375
- news/\_ id.vue pages
376
376
377
377
``` js
378
- import { NewsProxy } from ' ~/proxies'
378
+ import { NewsService } from ' ~/proxies'
379
379
380
- const proxy = new NewsProxy ()
380
+ const service = new NewsService ()
381
381
382
382
export default {
383
383
methods: {
384
384
async fetchNews (id ) {
385
385
try {
386
- const { data } = await proxy .find (id)
386
+ const { data } = await service .find (id)
387
387
this .detail = data
388
388
} catch (e) {
389
389
console .log (e)
0 commit comments