0.4.2 • Published 8 years ago

service-proxy v0.4.2

Weekly downloads
8
License
ISC
Repository
github
Last release
8 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

8 years ago

0.4.1

8 years ago

0.4.0

8 years ago

0.3.6

8 years ago

0.2.5

8 years ago

0.3.4

8 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago