0.4.2 • Published 6 years ago

service-proxy v0.4.2

Weekly downloads
8
License
ISC
Repository
github
Last release
6 years ago

service-proxy

superagent request proxy.

use

import ServiceProxy from 'service-proxy'

// text example
// https://httpbin.org/

const config = {
  test: {
    getTest: {
      type: 'GET',
      url: 'https://httpbin.org/get'
    },
    postTest: {
      type: 'POST',
      url: 'https://httpbin.org/post'
    },
    putTest: {
      type: 'PUT',
      url: 'https://httpbin.org/put'
    },
    deleteTest: {
      type: 'DELETE',
      url: 'https://httpbin.org/delete'
    },
    patchTest: {
      type: 'PATCH',
      url: 'https://httpbin.org/patch'
    }
  }
}

const sp = new ServiceProxy(config)

const testAPI = sp.make('test')

// example
testAPI.request('getTest', {
    query: {
      _: Date.now()
    }
  })
  .then(res => console.log(JSON.parse(res.text)))
  .catch(error => console.error('get.catch.error', error))

testAPI.request('postTest', {
    data: {
      now: Date.now()
    }
  })
  .then(res => console.log(JSON.parse(res.text)))
  .catch(error => console.error('post.catch.error', error))

testAPI.request('putTest')
  .then(res => console.log(JSON.parse(res.text)))
  .catch(error => console.error('put.catch.error', error))

testAPI.request('deleteTest')
  .then(res => console.log(JSON.parse(res.text)))
  .catch(error => console.error('delete.catch.error', error))

testAPI.request('patchTest')
  .then(res => console.log(JSON.parse(res.text)))
  .catch(error => console.error('patch.catch.error', error))

Cross-Origin Resource Sharing(CORS)

superagent withCredentials()

new ServiceProxy(config, { cors: true })
0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.6

6 years ago

0.2.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago