Socket
Socket
Sign inDemoInstall

@spinque/query-api

Package Overview
Dependencies
Maintainers
2
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spinque/query-api

JavaScript/TypeScript library to use the Spinque Query API in your project.


Version published
Weekly downloads
29
decreased by-3.33%
Maintainers
2
Weekly downloads
 
Created
Source

@spinque/query-api

JavaScript/TypeScript library to use the Spinque Query API in your project.

Usage

Defining queries

Defining a single query:

import { Query } from '@spinque/query-api';

const single_query: Query = {
  endpoint: 'movie_search',
  parameters: { terms: 'call me' }
};

Stacking queries, for example for faceted search:

const stacked_queries: Query[] = [{
  endpoint: 'movie_search',
  parameters: { terms: 'call me' }
}, {
  endpoint: 'genres'
}];

Fetching results

Fetching results for a single query using an instance of the Api class:

import { Api } from '@spinque/query-api';

const api = new Api({
  workspace: 'my-workspace',
  config: 'default',
  api: 'movies'
});

try {
  const response = await api.fetch(query, { count: 10, offset: 0 });
} catch (error: any) {
  console.error(error);
}

Fetching using custom HTTP-library

Getting the URL for a request to fetch it using your own HTTP-library of preference:

import { urlFromQueries } from '@spinque/query-api/utils';

const apiConfig = {
  workspace: 'my-workspace',
  config: 'default',
  api: 'movies'
};

const url = urlFromQueries(apiConfig, query, { count: 10, offset: 0 });

Vanilla JavaScript

This library can also be used without using TypeScript:

const sqa = require("@spinque/query-api");

const api = new sqa.Api({
  workspace: 'my-workspace',
  api: 'movies'
});

const query = {
  endpoint: 'search',
  parameters: { term: 'utrecht' }
};

try {
  const results = await api.fetch(query);
  console.log(results);
} catch (error) {
  console.log(error);
}

Keywords

FAQs

Package last updated on 07 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc