You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.0KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <div align="center">
  2. # portal
  3. > HTTP API clients ... simplified.
  4. </div>
  5. ## Installation
  6. ```
  7. npm install --save @ojizero/portal
  8. ```
  9. ## Usage
  10. Aimed to be used as a building block for API client libraries
  11. ```typescript
  12. /// In your library or definition file
  13. import portal from '@ojizero/portal'
  14. const client = portal({ baseUrl: 'some.base.url' }) // Initial configuration can be passed here
  15. // Get method without path variables
  16. client.route('someGetMethod', { path: '/some/path' })
  17. // Get method with path variables
  18. client.route('someGetMethodWithParam', { path: '/some/path/:withInnerVariable' })
  19. export default client
  20. /* ******************* */
  21. /// In your application
  22. import YourClient from 'your-client-module'
  23. const client = YourClient() // You can also pass additional options to futher configure the client
  24. const someGetMethodPromise = client.someGetMethod() // GET http://some.base.url/some/path
  25. const someGetMethodWithParamPromise = client.someGetMethodWithParam(5) // GET http://some.base.url/some/path/5
  26. ```