npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

super-http-client-js

v2.0.0

Published

Http Client Lib with segregated interfaces developed with clean architecture concepts by Superlógica Tecnologias S.A

Downloads

3

Readme

Super Http Client JS

What is Super Http Client?

Http Client lib for Node.js & TypeScript developed by Superlógica Tecnologias S.A

Getting started

To install the lib just run the command:

npm install @superlogica/super-http-client-js

Ready!

Now you can use the available interfaces and the adapter.

How Works?

The most basic possible use is to import default (adapter) and use it, as in the following example:

import SuperHttpClient from '@superlogica/super-http-client-js'

async function getAllCharacters() {
  const superHttpClient = new SuperHttpClient({
    baseURL: 'https://rickandmortyapi.com/api'
  })

  const characters = await superHttpClient.get({
    url: '/character'
  })

  return characters
}

You can also make named imports to use interfaces, that is, abstractions instead of injecting concrete classes, as in the following example:

First of all, it is possible to create a type to define what the response will be, for example, of a get request.

// characters-dto.ts

export type Info = {
  count: number
  pages: number
  next: string
  prev?: string
}

export type Character = {
  id: number
  name: string
  status: 'alive' | 'dead' | 'unknown'
  species: string
  type: string
  gender: 'male' | 'female' | 'genderless'
  origin: {
    name: string
    url: string
  }
  location: {
    name: string
    url: string
  }
  image: string
  episode: string[]
  url: string
  created: Date
}

Let's create a simple use case that basically lists all characters for a given API. For this, we will use the existing abstraction in the @superlogica/super-http-client-js lib, which is HttpGetClient

Note that when calling the get method, a parameter is passed to indicate the method's response type.

// get-all-characters-use-case.ts

import { HttpGetClient } from '@superlogica/super-http-client-js'

import { Info, Character } from './characters-dto'

export type Response = Info & Character

export class GetAllCharactersUseCase {

  // abstract dependency
  constructor(private readonly getCharacters: HttpGetClient) {}

  async execute() {
    return this.getCharacters.get<Response>({
      url: '/character'
    })
  }
}

Finally, in index file, for example, you can create a lib instance to inject the dependency into the use case constructor

// index.ts

const superHttpClient = new SuperHttpClientAdapter({
  baseURL: 'https://rickandmortyapi.com/api'
})

// inject dependency
const getAllCharactersUseCase = new GetAllCharactersUseCase(superHttpClient)

getAllCharactersUseCase.execute().then((response) => {
  console.log(response)
})