1.2.9 • Published 1 year ago

laravel-request v1.2.9

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year 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

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

1.1.45

1 year ago

1.1.49

1 year ago

1.1.48

1 year ago

1.1.47

1 year ago

1.1.46

1 year ago

1.2.9

1 year ago

1.1.41

2 years ago

1.1.44

2 years ago

1.1.43

2 years ago

1.1.42

2 years ago

1.1.38

2 years ago

1.1.37

2 years ago

1.1.39

2 years ago

1.1.40

2 years ago

1.1.36

2 years ago

1.1.29

2 years ago

1.1.28

2 years ago

1.1.30

2 years ago

1.1.34

2 years ago

1.1.33

2 years ago

1.1.32

2 years ago

1.1.31

2 years ago

1.1.35

2 years ago

1.1.27

2 years ago

1.1.26

2 years ago

1.1.25

2 years ago

1.1.24

2 years ago

1.1.23

2 years ago

1.1.22

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.1.16

2 years ago

1.1.15

2 years ago

1.1.14

3 years ago

1.1.13

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.10

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.0.0

3 years ago