Registry / devops / make-service

make-service

JSON →
library4.1.1jsnpmunverified

A type-safe thin wrapper around the fetch API for interacting with external APIs. Current stable version is 4.1.1, actively maintained with TypeScript support. It provides features like base URL configuration, automatic JSON body stringification, URL params and query composition, request/response transformers (e.g., case conversion), and runtime response parsing via standard-schema libraries. Unlike bare fetch, it offers type-safe response.json() (defaults to unknown instead of any), merges headers, and includes debugging via trace function. Requires Node >=18.

npm install make-service
INSTALL
IMPORT
SIG · MAKE-SERVICE
M
make-service
devopsjavascriptv4.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

makeService
import { makeService } from 'make-service'
const makeService = require('make-service')
ESM-only; CommonJS require() is not supported.
enhancedFetch
import { enhancedFetch } from 'make-service'
import enhancedFetch from 'make-service'
Named export, not default export.
typedResponse
import { typedResponse } from 'make-service'
Used for type-safe response handling.

Creates a service with base URL and headers, makes a GET request with params and query, then parses the response with or without Zod schema.

import { makeService } from 'make-service' const service = makeService('https://api.example.com', { headers: { Authorization: 'Bearer ' + (process.env.API_KEY ?? ''), }, }) const response = await service.get('/users', { params: { id: '123' }, query: { page: '1' }, }) const users = await response.json() // users is typed as unknown // With runtime schema validation (using zod): import { z } from 'zod' const UserSchema = z.object({ id: z.number(), name: z.string(), }) const validatedUsers = await response.json(z.array(UserSchema)) // validatedUsers is typed as z.infer<typeof UserSchema>[]
Debug
Known issues
breakingVersion 4.x changed the signature of makeService: the second argument is now an options object instead of individual parameters.
fix
Update calls from makeService(baseURL, headers, options) to makeService(baseURL, { headers, ...options }).
affects: >=4.0.0 <5.0.0
deprecatedThe old typedFetch export has been deprecated in favor of typedResponse.
fix
Use typedResponse instead.
affects: >=4.0.0
gotcharesponse.json() returns unknown by default; if you expect a specific type you must provide a schema or cast.
fix
Pass a validation schema to response.json(schema) or use 'as' type assertion.
affects: >=4.0.0
gotchaThe transformer feature can modify request/response bodies but is opt-in; it does not automatically convert case.
fix
Provide transformRequest and transformResponse options explicitly.
affects: >=4.0.0
gotchamakeService requires Node >=18 due to reliance on the global fetch.
fix
Ensure Node.js version is 18 or higher.
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: makeService is not a function
Using CommonJS require() instead of ESM import.
fix
Use import { makeService } from 'make-service' and ensure your environment supports ES modules.
Cannot find module 'make-service'
Package not installed or import path incorrect.
fix
Run 'npm install make-service' and verify the import statement.
Property 'json' does not exist on type 'Response'
Using raw fetch Response instead of typedResponse from makeService.
fix
Use service.get() which returns a typedResponse, not bare fetch.
Uncaught TypeError: Failed to execute 'json' on 'Response': body stream already read
Calling response.json() or response.text() multiple times.
fix
Call response.json() only once; clone the response if you need multiple reads.
Upgrade
Version history
4.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
make-service — npm install make-service · libregistry