@shaggytools/nhtsa-api-wrapper
Version:
Universal javascript wrapper for the NHTSA.dot.gov VPIC 'vehicles' API, useful for VIN decoding, etc.
54 lines • 2.06 kB
TypeScript
/**
* @module api/useNHTSA
* @category API
*/
import type { NhtsaResponse, QueryStringParams } from '../types';
export type CreateUrlOptions = {
endpointName: string;
allowEmptyParams?: boolean;
includeQueryString?: boolean;
path?: string;
params?: QueryStringParams;
saveUrl?: boolean;
};
/**
* `useNHTSA` returns a composable object containing helper functions for working with the VPIC
* API. It is used internally by the package and by users to make direct requests to the VPIC API.
*
* It returns an object containing methods for making HTTP requests to the VPIC API. All
* request methods return a Promise that resolves to an object containing the full response data.
*
* The functions returned by the composable are:
*
* - `createCachedUrl` - Builds the URL string and stores it in internal state
*
* - `getCachedUrl` - Gets the URL stored in internal state
*
* - `setCachedUrl` - Directly sets the URL internal state, does not check if URL is valid
*
* - `clearCachedUrl` - Clears the URL stored in internal state
*
* - `createUrl` - Returns a built URL string but does not store it in internal state
*
* - `createPostBody` - Creates a POST body string from an object of key/value pairs
*
* - `get` - Makes a GET request, uses the internal url variable if no URL is provided
*
* - `post` - Makes a POST request, uses the internal url variable if no URL is provided
*
*/
export declare const useNHTSA: () => {
setCachedUrl: (url: string) => string;
getCachedUrl: () => string;
clearCachedUrl: () => string;
createCachedUrl: (input: CreateUrlOptions | string) => string;
createUrl: (options: CreateUrlOptions) => string;
createPostBody: (data: string) => string;
get: <T>(url?: string | CreateUrlOptions, options?: RequestInit & {
saveUrl?: boolean;
}) => Promise<NhtsaResponse<T>>;
post: <T_1>(url?: string | CreateUrlOptions, options?: RequestInit & {
saveUrl?: boolean;
}) => Promise<NhtsaResponse<T_1>>;
};
//# sourceMappingURL=useNHTSA.d.ts.map