Skip to content
This repository has been archived by the owner on Jan 10, 2021. It is now read-only.

bjbr-dev/restclient.js

Repository files navigation

RestClient

npm version npm downloads Build Status

Perform HTTP requests (preferably REST style!) from NodeJS or client-side javascript.

Features

  • Simple interface backed by middleware for complete flexibility
  • Promise based, with cancellation support
  • Automatic JSON serialization
  • Optional, automatic validation of server responses

Browser Support

Chrome Firefox Safari Opera Edge IE
Latest ✔ Latest ✔ Latest ✔ Latest ✔ Latest ✔ 11 ✔

Installing

Using npm:

$ npm install @berkeleybross/restclient

Until this project reaches a 1.0 release, breaking changes will be released with a new minor version. For example 0.5.1, and 0.5.4 will have the same API, but 0.6.0 will have breaking changes.

Examples

Perform a GET request. The following performs a GET to /api/search?term=foo%20bar, and throws an error if the response code is not "success" (between 200 and 300)

return await this.client.$get(['/api/search', { term: 'foo bar' }])

Perform a PUT request. The following performs a PUT to '/api/users/5' with JSON body of { "name": "John Smith" }.

It will throw an error only if their was an HTTP transport error (e.g. network disconnected). Otherwise it will return an enum (string) describing the result

async function example() {
  const response = await this.client.put(['/api/users/{id}', { id: 5 }], {
    name: 'John Smith'
  })

  // Could also check response.success !== false
  if (response.status === 201) {
    return 'Created'
  } else {
    return 'Unknown error'
  }
}

For more examples, please read the Wiki.

Report Issues

For any issues or feature requests, we would really appreciate it if you report them using our issue tracker.

Contributing

Contributing to Coding with Chrome is subject to the guidelines in the CONTRIBUTING.md file, which, in brief, requires that contributors sign the [Individual Contributor License Agreement (CLA)][3].

For more information about develop for Coding with Chrome, please check doc/DEVELOPMENT.md

Licensing

Released under The MIT License. Copyright (c) berkeleybross.

Credits

RestClient is made possible by other open source software.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published