8.21.0 • Published 2 years ago

@execonline-inc/appy v8.21.0

Weekly downloads
15
License
ISC
Repository
github
Last release
2 years ago

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);
8.18.0

2 years ago

8.17.1

2 years ago

8.20.0

2 years ago

8.21.0

2 years ago

8.19.0

2 years ago

8.16.0

2 years ago

8.17.0

2 years ago

8.15.0

2 years ago

8.14.0

2 years ago

8.13.0

2 years ago

8.12.0

2 years ago

8.10.0

2 years ago

8.11.0

2 years ago

8.9.0

2 years ago

8.8.0

2 years ago

8.5.0

2 years ago

8.7.0

2 years ago

8.6.0

2 years ago

8.4.0

3 years ago

8.3.0

3 years ago

8.2.0

3 years ago

8.1.0

3 years ago

8.1.1

3 years ago

8.0.0

3 years ago

7.0.0

3 years ago

6.0.0

3 years ago

5.1.0

3 years ago

5.0.0

3 years ago

4.0.0

3 years ago

3.2.0

4 years ago

3.1.0

4 years ago

3.0.0

4 years ago

2.3.1

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.0.1

4 years ago