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

maggo

v1.1.0

Published

A versatile HTTP client library for simplifying API requests and handling responses with ease. Supports GET, POST, PUT, and DELETE methods.

Downloads

11

Readme

Get started

Maggo is a tool that helps you in the process of making http requests on the web (inspired by axios) supporting the main http methods (GET, POST, PUT, DELETE) plus some added extras to speed up very specific processes and solve common problems. focused on simplicity and minimalism

Your first GET request

After installing the pagacke using npm or yarn, just import a basic instance and use the method you need. In this case we will make a GET request

import { maggo } from "maggo/request";

maggo.get("https://jsonplaceholder.typicode.com/posts");

This would be the minimum to be able to make a request. From here we can manipulate the response to work with it in this way :

import maggo from "maggo/request";

const response = await maggo.get("https://jsonplaceholder.typicode.com/posts");
console.log(response.body);

Or this way :

import { maggo } from "maggo/request";

maggo
  .get("https://jsonplaceholder.typicode.com/posts")
  .then((res) => console.log(res.body))
  .catch((err) => console.error(err));

Installing

Using npm

$ npm i maggo

Using pnpm

$ pnpm i maggo

Using yarn

$ yarn add maggo

Usage

Instances

Once installed Maggo you have two options to be able to use it and start making requests. The first method is using a basic instance with the same name since it is a re-export from the Maggo factory as seen in the example in the Get started section. This would be the easiest and fastest method.

import { maggo } from "maggo/request";

// Using a base instance
const respone = maggo.get("https://jsonplaceholder.typicode.com/posts");
console.log(response.body);

The second method would be to create an instance of the Maggo class which you can use exactly the same as the base instance with the difference that with this method you can assign a base URL for all requests made using this instance.

import Maggo from "maggo";

// Creating the instance with a base URL
const maggo = new Maggo("https://jsonplaceholder.typicode.com");

// This will do a GET request to :
// https://jsonplaceholder.typicode.com/post
maggo.get("/post");

Response shape

The response to a request includes the following details.

{
  // `details` will contain all the information of
  // the request itself such as headers, cookies, etc.
  details: Promise;

  // `body` is the response that was provided by the server
  body: {
  }

  // `status` is the HTTP status code from the server response
  status: 200;
}

When using then, the response will be handled like this:

maggo.get("https://jsonplaceholder.typicode.com/posts").then((response) => {
  console.log(response.details);
  console.log(response.body);
  console.log(response.status);
});

Templates

Using templates you can tell Maggo what form the server response (which comes in the body object) is expected to have using type or typescript interfaces.

import { maggo } from "maggo/request";

interface Post {
  userId: number;
  id: number;
  title: string;
  body: string;
}

maggo.get<Post>("https://jsonplaceholder.typicode.com/posts");

License

MIT