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

@execonline-inc/appy

v8.21.0

Published

Call api patterns around ajaxian http tasks

Downloads

13

Readme

appy

The appy package provides functions to interface with HATEOAS API endpoints.

Types

MissingApplicationId

interface MissingApplicationId {
  kind: 'missing-application-id';
}

AppyError

import { MissingApplicationId } from '@execonline-inc/appy';
import { HttpError } from 'ajaxian';

type AppyError = HttpError | MissingApplicationId;

HReferenceable

import { HttpError, Method } from 'ajaxian';

interface HReferenceable {
  href: string;
  method: Method;
}

Functions

request

This curried function creates an HTTP request Task using a given authentication token, HATEOAS link, and payload data, and decodes the response using the given decoder.

import { AppyError, HReferenceable, request } from '@execonline-inc/appy';
import Decoder, { succeed } from 'jsonous';
import { Maybe, just } from 'maybeasy';
import Task from 'taskarian';

const token: Maybe<string> = just('3ad1afde-6d9f-4e29-97d4-4396f891267f');
const link: HReferenceable = { href: 'https://example.com/', method: 'get' };
interface Response {}
const decoder: Decoder<Response> = succeed({});
const payload = {};

const req: Task<AppyError, RequestBuilder<Response>> = request(token)(link, decoder, payload);

callApi

Similar to request, this function creates an HTTP request Task. The significant differences are that a given Task is executed when the response indicates that the authentication is invalid, and the ultimate return value is an object of the decoded type itself, not one wrapped in a RequestBuilder object.

import { AppyError, callApi, HReferenceable } from '@execonline-inc/appy';
import Decoder, { succeed } from 'jsonous';
import { Maybe, just } from 'maybeasy';
import Task from 'taskarian';

const token: Maybe<string> = just('3ad1afde-6d9f-4e29-97d4-4396f891267f');
const link: HReferenceable = { href: 'https://example.com/', method: 'get' };
const whenUnauthenticated: Task<never, void> = new Task(() => noop);
interface Response {}
const decoder: Decoder<Response> = succeed({});
const payload = {};

const req: Task<AppyError, Response> = callApi(token)(whenUnauthenticated)(decoder, payload)(link);

postToApi

Similar to callApi, this function creates an HTTP request Task, but it's hardcoded for the post verb and does not decode the response.

import { AppyError, HReferenceable, postToApi } from '@execonline-inc/appy';
import { Maybe, just } from 'maybeasy';
import Task from 'taskarian';

const token: Maybe<string> = just('3ad1afde-6d9f-4e29-97d4-4396f891267f');
const link: HReferenceable = { href: 'https://example.com/', method: 'post' };
const whenUnauthenticated: Task<never, void> = new Task(() => noop);
const payload = {};

const req: Task<AppyError, string> = postToApi(token)(whenUnauthenticated)(payload)(link);

putToApi

Similar to callApi, this function creates an HTTP request Task, but it's hardcoded for the put verb and does not decode the response.

import { AppyError, HReferenceable, putToApi } from '@execonline-inc/appy';
import { Maybe, just } from 'maybeasy';
import Task from 'taskarian';

const token: Maybe<string> = just('3ad1afde-6d9f-4e29-97d4-4396f891267f');
const link: HReferenceable = { href: 'https://example.com/', method: 'put' };
const whenUnauthenticated: Task<never, void> = new Task(() => noop);
const payload = {};

const req: Task<AppyError, string> = putToApi(token)(whenUnauthenticated)(payload)(link);

deleteToApi

Similar to callApi, this function creates an HTTP request Task, but it's hardcoded for the delete verb, does not decode the response, and does not accept request payload data.

import { AppyError, deleteToApi, HReferenceable } from '@execonline-inc/appy';
import { Maybe, just } from 'maybeasy';
import Task from 'taskarian';

const token: Maybe<string> = just('3ad1afde-6d9f-4e29-97d4-4396f891267f');
const link: HReferenceable = { href: 'https://example.com/', method: 'delete' };
const whenUnauthenticated: Task<never, void> = new Task(() => noop);

const req: Task<AppyError, string> = deleteToApi(token)(whenUnauthenticated)(link);

getFromApi

Similar to callApi, this function creates an HTTP request Task, but it's hardcoded for the get verb and does not decode the response.

import { AppyError, getFromApi, HReferenceable } from '@execonline-inc/appy';
import { Maybe, just } from 'maybeasy';
import Task from 'taskarian';

const token: Maybe<string> = just('3ad1afde-6d9f-4e29-97d4-4396f891267f');
const link: HReferenceable = { href: 'https://example.com/', method: 'get' };
const whenUnauthenticated: Task<never, void> = new Task(() => noop);
const payload = {};

const req: Task<AppyError, string> = getFromApi(token)(whenUnauthenticated)(payload)(link);

getRespFromApi

Similar to callApi, this function creates an HTTP request Task, but it's hardcoded for the get verb, does not decode the response, and returns the entire successful response object rather than just its body.

import { AppyError, getRespFromApi, HReferenceable } from '@execonline-inc/appy';
import { Maybe, just } from 'maybeasy';
import Task from 'taskarian';

const token: Maybe<string> = just('3ad1afde-6d9f-4e29-97d4-4396f891267f');
const link: HReferenceable = { href: 'https://example.com/', method: 'get' };
const whenUnauthenticated: Task<never, void> = new Task(() => noop);
const payload = {};

const req: Task<AppyError, HttpSuccess<string>> = getRespFromApi(token)(whenUnauthenticated)(
  payload
)(link);