Socket
Book a DemoInstallSign in
Socket

nexus-http

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

nexus-http

nexus-http is a simple http client that allows you to make requests easily.

unpublished
latest
Source
npmnpm
Version
2.4.1
Version published
Maintainers
1
Created
Source

Description 📄

nexus-http is a simple http client that allows you to make requests easily with fetch API.

Install 📦️

npm i --save nexus-http

How to use ✏️

In a js file remove the extra typing from the nexusHttp.get part and .then.

import { nexusHttp, HttpError, HttpResponse } from 'nexus-http';

nexusHttp.get<User[]>('http://localhost:3000/api/users', {
  query: {
    page: 1,
    limit: 12,
    deleted: false
  }
})
  .then((response: HttpResponse<User[]>) => {
      // Add some logic when status is >= 200 and <= 299
  })
  .catch((response: HttpResponse<HttpError>) => {
      // Add some logic on error
  })
  .finally(() => {
    // Add some logic after success or error
  });

With baseUrl:

import { nexusHttp, HttpError, HttpResponse } from 'nexus-http';

nexusHttp.setBaseUrl('http://localhost:3000/api/');

nexusHttp.get<User[]>('/users') // url before adding query params: http://localhost:3000/api/users
  .then((response: HttpResponse<User[]>) => {
      // Add some logic when status is >= 200 and <= 299
  })
  .catch((response: HttpResponse<HttpError>) => {
      // Add some logic on error
  })
  .finally(() => {
    // Add some logic after success or error
  });

Create your own instance:

import { nexusHttp, HttpError, HttpResponse } from 'nexus-http';

const nexusHttp = new NexusHttp();

nexusHttp.get<User[]>('http://localhost:3000/api/users')
  .then((response: HttpResponse<User[]>) => {
      // Add some logic when status is >= 200 and <= 299
  })
  .catch((response: HttpResponse<HttpError>) => {
      // Add some logic on error
  })
  .finally(() => {
    // Add some logic after success or error
  });

Client

if fetch is not supported, the client use XmlClient by default.

import { nexusHttp, HttpError, HttpResponse, XmlClient } from 'nexus-http';

const nexusHttp = new NexusHttp();
nexusHttp.useClient(XmlClient);
// Now this instance of nexusHttp use the XmlClient (XMLHttpRequest)

nexusHttp.get<User[]>('http://localhost:3000/api/users')
  .then((response: HttpResponse<User[]>) => {
      // Add some logic when status is >= 200 and <= 299
  })
  .catch((response: HttpResponse<HttpError>) => {
      // Add some logic on error
  })
  .finally(() => {
    // Add some logic after success or error
  });

Keywords

typescript

FAQs

Package last updated on 19 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts