Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fetch-safely

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-safely

Runtime data validation of HTTP requests.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

API Request & Response Runtime Validation

Runtime data validation of HTTP requests.

For those who put too much trust in TypeScript

Examples

Path based validation

import fetchValidationFactory from './fetchValidationFactory';

// `fetch-validated.ts`
export const paths = {
  `/api/user`: checkUserSchema,
  `/api/repos/`: checkRepoSchema,
  `GET:/api/notes`: data => schema_id_and_note.parse(data),
  `POST:/api/notes`: {
    request: (data) => schema_note.parse(data),
    response: (data) => schema_id_and_note.parse(data),
  }
};

const fetchValidated = fetchValidationFactory(paths);
export default fetchValidated;

Zod Schema Validation

import { z } from "zod";

export default function checkUserSchema(input: unknown) {
  return GitUserSchema.parse(input);
}

const GitUserSchema = z.object({
  login: z.string().required(),
  id: z.number().required(),
  nodeId: z.string().required(),
  avatarUrl: z.string().required(),
  gravatarId: z.string().required(),
  url: z.string().required(),
  htmlUrl: z.string().required(),
  followersUrl: z.string().required(),
  followingUrl: z.string().required(),
  gistsUrl: z.string().required(),
  starredUrl: z.string().required(),
  subscriptionsUrl: z.string().required(),
  organizationsUrl: z.string().required(),
  reposUrl: z.string().required(),
  eventsUrl: z.string().required(),
  receivedEventsUrl: z.string().required(),
  type: z.string().required(),
  siteAdmin: z.boolean().required(),
  name: z.string().required(),
  company: z.string().required(),
  blog: z.string().required(),
  location: z.string().required(),
  email: z.string().email().required(),
  hireable: z.boolean().required(),
  bio: z.string().required(),
  twitterUsername: z.string().required(),
  publicRepos: z.number().required(),
  publicGists: z.number().required(),
  followers: z.number().required(),
  following: z.number().required(),
  createdAt: z.date().required(),
  updatedAt: z.date().required()
});
export type GitUser = z.infer<typeof GitUserSchema>;

FAQs

Package last updated on 15 Dec 2021

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