xeta

lightweight http client for web and node

Usage no npm install needed!

<script type="module">
  import xeta from 'https://cdn.skypack.dev/xeta';
</script>

README

xeta

CircleCI NPM Downloads node License MIT

Observable based http client for web and node

Highlights

  • Written in Typescript
  • Works in Browser and Node
  • Easy Observable based API

Installation

npm:

$ npm install xeta

yarn:

$ yarn add xeta

Usage

lightweight http client for web and node


  const { xeta } = require('xeta');

  xeta.get('https://jsonplaceholder.typicode.com/todos/1')
  .subscribe((response) => {
    // handle success
    console.log(response);
  },
  (error) => {
    // handle error
    console.error(error)
  },
  ()=>{
    // handle completion
    console.log('complete');
  }
  );

  // Promise

  xeta.get('https://jsonplaceholder.typicode.com/todos/1')
  .toPromise()
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .finally(function () {
    // always executed
  });


  // async/await
  async function getTodo() {
    try {
      const response = await xeta.get('https://jsonplaceholder.typicode.com/todos/1').toPromise();
      console.log(response);
    } catch (error) {
      console.error(error);
    }
  }

License

MIT © Nivrith