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

@attivio/fetch-utils

v0.0.9

Published

Wrapper around the fetch() API to use when communicating with the Attivio REST APIs authenticated with SAML.

Downloads

8

Readme

@attivio/fetch-utils

[![TravisCI][build-badge]][build] [![npmjs][npm-badge]][npm]

This ia a library to use when accessing Attivio REST APIs with SAML-based authentication from a serverless web application such as a React single-page application. It contains a single function, FetchUtils.fetch() which you can use instead of calling the built-in fetch() API directly. This method does a few useful things for you:

  • It sets the headers and parameters to the fetch() call in a consistent manner
  • It handles cases where the fetch() call fails because of a potentially missing authentication token, redirecting to the special login API call on the servlet to trigger the authentication
  • It provides a consistent way to receive results and error messages

Using the Library

To use @attivio/fetch-utils:

  1. Add it as a dependency to your project:
npm install --save @attivio/fetch-utils
  1. Import the FetchUtils class into your application code where you will need to access the Attivio REST APIs:
import FetchUtils from '@attivio/fetch-utils';
  1. Finally, use it to access the REST APIs you need:
const baseUri = 'http://myhost:8080/searchui/';
const restEndpoint = 'rest/serverDetailsApi/user';
const callback = (result: any | null, error: string | null) => {
  if (result) {
    console.log('The API call returned this result', result);
  } else if (error) {
    console.log('The API call returned this error', error);
  }
};

FetchUtils.fetch(baseUri, restEndpoint, null, callback, 'GET', 'An error occured.');

Using the FetchUtils.fetch() Method

The FetchUtils.fetch() method takes the following parameters:

| Parameter | Type | Description | |-----------|------|-------------| | baseUri | string | the base URI for the Attivio servlet, up to and including the servlet context part of the path, including the trailing slash (e.g., /searchui/) | | endpointUri | string | the part of the URI specific to the REST endpoint you want to access | | payload | any | a JavaScript object containing the palyload to pass as parameters to the REST call; will be converted into a JSON string -- pass null if no payload is needed | | callback | function (see below) | the function called when the fetch() call returns a result or an error | | method | HttpMethod (see below) | the HTTP method to use when making the fetch request | | defaultErrorMessage | string | the message that should be passed to the callback if an error occurs but no message can be obtained from the fetch() call |

The callback function is called asynchronosly, once there is either a successful result or an error from the fetch() call. Its parameters are:

| Parameter | Type | Description | |-----------|------|-------------| | result | any | null | a JavaScript object containing the result of a successful fetch() call; if an error occurred, this will be null | | error | string | null | the error message describing what went wrong if the fetch() call didn't succeed; if it did succeed, this will be null |

The type HttpMethod is one of the following strings: 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', or 'PATCH'.