1.2.9 • Published 4 months ago

laravel-request v1.2.9

Weekly downloads
-
License
MIT
Repository
-
Last release
4 months ago

Install

npm install laravel-request

Connected package

https://github.com/olegstan/laravel-rest

set domain resolver before any request

Api.domainResolver = () => {
    try {
        return Environment.get('REACT_APP_API_URL');
    } catch (e) {
        console.log(e)
        return null;
    }
}

set auth token resolver before any request

default token resolver, you can redefine it to any other

Api.tokenResolver = async () => {
    try {
        return await localStorage.getItem('api_token'); 
    } catch (e) {
        console.log(e)
        return null;
    }
}

Usage get data

Api.get('active-trade', 'index')
      .where('active_id', 115)
      .with('currency')
      .with('to_account', 'to_account.currency')
      .with('from_account', 'from_account.currency')
      .orderBy('trade_at', 'DESC')
      .all((response) => {
        //success
      }, () => {
        //error
      })
}}     

or

Api.get('active-trade', 'index')
      .where('id', 115)
      .with('currency')
      .with('to_account', 'to_account.currency')
      .with('from_account', 'from_account.currency')
      .orderBy('trade_at', 'DESC')
      .first((response) => {
        //success
        
      }, () => {
        //error
      })
}}

You can use

all or first or paginate

usage POST data

Api.post('active', 'store', {
      user_id: this.props.client.id,
      type: 2,
      type_id: item.type_id
    })
      .call((response) => {
        //success
      }, (response) => {
        //error
      });

response must be like below, for 200 status should contains key "result" with text "success"

{ "meta": [], "result": "success", "data": [], }

you can cancel request by

let cancelTokenSource = Api.get('active', SearchAllTypesHelper.ALL_TYPES, {
            item_search: searchQuery,
            user_id: clientId,
            search_stock: 1
        }).call(({data}) => {}, () => {}).getSource()
        
cancelTokenSource.cancel();
        
1.2.8

4 months ago

1.2.7

4 months ago

1.2.6

4 months ago

1.2.5

4 months ago

1.2.4

4 months ago

1.2.3

4 months ago

1.2.2

4 months ago

1.2.1

4 months ago

1.1.45

4 months ago

1.1.49

4 months ago

1.1.48

4 months ago

1.1.47

4 months ago

1.1.46

4 months ago

1.2.9

4 months ago

1.1.41

10 months ago

1.1.44

9 months ago

1.1.43

10 months ago

1.1.42

10 months ago

1.1.38

1 year ago

1.1.37

1 year ago

1.1.39

1 year ago

1.1.40

1 year ago

1.1.36

1 year ago

1.1.29

1 year ago

1.1.28

1 year ago

1.1.30

1 year ago

1.1.34

1 year ago

1.1.33

1 year ago

1.1.32

1 year ago

1.1.31

1 year ago

1.1.35

1 year ago

1.1.27

1 year ago

1.1.26

1 year ago

1.1.25

1 year ago

1.1.24

1 year ago

1.1.23

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.16

2 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.0.0

2 years ago