Registry / devops / axios-retrofit

axios-retrofit

JSON →
library2.0.2jsnpmunverified

A declarative, decorator-based HTTP client library for JavaScript/TypeScript that mimics Android's Retrofit pattern, built on top of axios. Current stable version is 2.0.2. Release cadence is low, with infrequent updates. Key differentiators: uses ES decorators for defining API endpoints, supports path parameters, headers, and body annotations, integrates with axios interceptors. Compared to alternatives like fetch or raw axios, it provides a structured, annotation-driven approach suitable for TypeScript projects seeking a Retrofit-like experience.

npm install axios-retrofit
INSTALL
IMPORT
SIG · AXIOS-RETROFIT
A
axios-retrofit
devopsjavascriptv2.0.2
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.

BaseService
import { BaseService } from 'axios-retrofit'
import BaseService from 'axios-retrofit'
Named export; no default export exists.
GET
import { GET } from 'axios-retrofit'
import { Get } from 'axios-retrofit'
Decorators are all uppercase (GET, POST, PUT, etc.). Case-sensitive.
ServiceBuilder
import { ServiceBuilder } from 'axios-retrofit'
import { ServiceBuilder } from 'axios-retrofit/dist/...'
Direct import from package root works; avoid subpath imports.

Shows a basic Retrofit-style service definition with GET decorator, path parameter, and header injection, then builds and calls it.

import { GET, BasePath, Header, Path, Body, BaseService, ServiceBuilder, Response } from "axios-retrofit"; interface User { id?: number; name: string; email: string; } @BasePath("/api/v1") class UserService extends BaseService { @GET("/users/{userId}") async getUser(@Header("Authorization") authorization: string, @Path("userId") userId: number): Promise<Response<User>> { return <Response<User>>{}; } } (async () => { const token = process.env.API_KEY ?? "default-token"; const userService = new ServiceBuilder() .setEndpoint("https://example.com") .build(UserService); const response = await userService.getUser(token, 1); console.log(response.data); })();
Debug
Known issues
gotchaDecorators require TypeScript experimentalDecorators and emitDecoratorMetadata enabled.
fix
Add "experimentalDecorators": true and "emitDecoratorMetadata": true in tsconfig.json compilerOptions.
affects: >=1.0.0
gotchaClass methods must return a Promise<Response<T>>; the default method body is empty (returns {}), which will be replaced at runtime.
fix
Ensure method signatures include return type Promise<Response<T>> and type assertion as shown. Do not add implementation.
affects: >=1.0.0
deprecatedThe package is no longer actively maintained; last release was 2.0.2 on 2020-09-19. No updates for axios compatibility or bug fixes.
fix
Consider migrating to a maintained alternative like angular or fetch-based wrapper if modern features are needed.
affects: >=2.0.2
breakingVersion 2.0.0 changed the package name from 'ts-retrofit' to 'axios-retrofit'. Breaking change for existing users.
fix
Update import to 'axios-retrofit' and reinstall.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: Class extends value undefined is not a constructor or null
BaseService is not imported correctly, usually because of mismatched package name or missing named import.
fix
Ensure you have 'import { BaseService } from "axios-retrofit"' and not a default import.
TS1206: Decorators are not valid here.
Decorators used in a non-class context or without proper module configuration.
fix
Enable 'experimentalDecorators' in tsconfig.json and ensure decorators are applied to class methods.
Uncaught TypeError: (0 , axios_retrofit_1.GET) is not a function
CommonJS require is used in a CommonJS environment but the package only supports named exports properly.
fix
Use ES import syntax: import { GET } from 'axios-retrofit' instead of const { GET } = require('axios-retrofit').
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
axiosrequiredCore HTTP client dependency
Agent activity
36 hits · last 30 days
node
34
OpenAI (training)
1
Resources
axios-retrofit — npm install axios-retrofit · libregistry