New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pentops/jsonapi-request

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pentops/jsonapi-request

A TypeScript fetch wrapper for making requests to [jsonapi](https://github.com/pentops/jsonapi) projects.

  • 0.0.7
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
21
decreased by-8.7%
Maintainers
0
Weekly downloads
 
Created
Source

jsonapi-request

A TypeScript fetch wrapper for making requests to jsonapi projects.

Basic use example:

import { buildMergedRequestInit, buildSplitRequestInit, makeRequest } from '@pentops/jsonapi-request';

interface LoginRequest {
  username: string;
  password: string;
}

interface LoginResponse {
  token: string;
}

export async function login(request: LoginRequest): Promise<LoginResponse> {
  return makeRequest<LoginResponse, LoginRequest>(...buildMergedRequestInit('POST', '/api/v1', '/login', request));
};

interface GetUserRequestPathParameters {
  id: string;
}

interface GetUserRequestQueryParameters {
  includeProfile?: boolean;
}

interface User {
  id: string;
  username: string;
  email: string;
}

interface UserResponse {
  user: User;
}

export async function getUser(id: string, includeProfile?: boolean): Promise<UserResponse> {
  return makeRequest<UserResponse>(...buildSplitRequestInit<GetUserRequestPathParameters, GetUserRequestQueryParameters>('GET', '/api/v1', '/users/:id', { id }, { includeProfile }));
}

buildSplitRequestInit

Use buildSplitRequestInit if your types are separated into request bodies, path parameters, and query parameters.

buildMergedRequestInit

Use buildMergedRequestInit if your types are merged into a single request type. Path parameters (denoted using colon format, e.g., :id) are replaced with the values in the request path. Other parameters will be added to the query string for GET requests and the request body for other requests.

Peer Dependencies

You will need to have uuid installed as a peer dependency.

FAQs

Package last updated on 07 Dec 2024

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