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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@apaq/leap-http

v1.0.9

Published

<p align="center"> <b>Leap Http</b> provides a simple Rest Client <br> for communicating with <b>REST APIs</b> in <b>a browser</b>.</b> </p>

Downloads

17

Readme

Leap Http

It's like Spring's RestTemplate for Javascript

  • It uses Fetch API underneath.
  • Message Formatters: Add any message formatter you want for converting response into Javascript objects. Out of the box it will parse and format JSON(including dates) as well as blobs.
  • Error handling: Easily add your own error handler.
  • Interception: Intercept any HTTP request for specialized handling.
  • Request Factory: Create specialized HTTP Request for authentication etc.
  • TypeScript: Supports TypeScript
import { RestTemplate } from '@apaq/leap-http'

const interface Cat {
    name: string;
    createdDate: Date;
}

const rest = new RestTemplate();
rest.getForObject<Cat>('https://myserver/cats/cat-1').then(cat => {
    //=> {name: "Garfield", createdAt: <date object>}
});

The library is available as an npm package. To install the package run:

npm install @apaq/leap-http --save
# or with yarn
yarn add @apaq/leap-http

Converters

leap-http allows for adding custom message converters, but comes with 2 builtin: JsonMessageConverter and BlobMessageConverter.

JsonMessageConverter

This converter converts from and to JSON including Date type when content type is application/json. In order to parse and format dates it makes use of date-fns.

BlobMessageConverter

This converter takes anything not already handled by other converters as blob input.

Custom converters

You can add any message conversion you'ld like by implementing the HttpMessageConveter interface.

class XmlMessageConverter implements HttpMessageConverter {
    readonly supportedMediaTypes: string[] = ['application/xml'];
    
    public canRead(mediaType: string): boolean { return this.supportedMediaTypes.includes(mediaType); }

    public canWrite(data: any): boolean { return typeof (data) === 'object'; }

    read(response: Response): Promise<any> {
        // handle reading xml from response and converting it to an object.
    }

    write(data: any): Promise<{headers: Headers, body: BodyInit}> {
        // return headers with corrent content type and convert data to xml.
    }
}

const rest = new RestTemplate();
rest.httpMessageConverters = [new XmlMessageConverter()];

let cat: Cat = { name: 'Garfield' };
cat = rest.postForObject<Cat>('https://myserver/cats', cat);

Error handling

For easy error handling, you can set a custom error interceptor on the RestTemplate object. The error handler simply needs to implement the ErrorHandler interface.

class MyErrorHandler implements ErrorHandler {
    hasError(response: Response): boolean {
        return !response.ok;
    }

    handleError(response: Response): Promise<void> {
        const statusCode = response.status;
        if (statusCode !== 200) {
            throw new Error('Response was not ok.');
        }
    }
}

const rest = new RestTemplate();
rest.errorHandler = new MyErrorHandler();

rest.getForObject<Cat>('https://none-existing');
//=> Throws error

License

MIT