
Security News
Suno Breached via Shai-Hulud Worm, Leaked Code Exposes AI Music Scraping
A Shai-Hulud infection exposed Suno's source code, which shows the AI music startup stream-ripped tracks to train its models.
@r2don/nest-http-interface
Advanced tools
HTTP client for Nest framework, inspired by HTTP interface in Spring 6
This library is inspired by the HTTP interface in Spring 6 and provides a similar API for Nest.js.
fetch internally)$ npm install @r2don/nest-http-interface
First, the module we created must be imported into AppModule.ts:
import { Module } from '@nestjs/common';
import { HttpInterfaceModule } from '@r2don/nest-http-interface';
@Module({
imports: [HttpInterfaceModule.forRoot()],
})
export class AppModule {}
Then, you need to create the desired HTTP service and specify several decorators:
import {
HttpInterface,
GetExchange,
ResponseBody,
imitation,
PathVariable,
} from '@r2don/nest-http-interface';
@HttpInterface('https://example.com/api') // base url
class UserHttpService {
@GetExchange('/users/{id}') // path
@ResponseBody(UserResponse) // response dto
async request(@PathVariable('id') id: number): Promise<UserResponse> {
return imitation(id); // this is a mock function to prevent the type error
}
}
After adding the service to the providers in the module, you can use it and make HTTP requests when calling
the request method:
@Injectable()
class UserService {
constructor(private readonly client: UserHttpService) {}
async getUser(id: number): Promise<UserResponse> {
return this.client.request(id);
}
}
@HttpInterface(): Marks the class as an HTTP service.
@{HTTP Method}Exchange(path: string, options?: HttpClientOptions): Marks the method as an HTTP request method, with path being the request's
path or full URL.
@GraphQLExchange(query: string, url = '/graphql', options?: HttpClientOptions): Marks the method as a GraphQL request method, with query being
the GraphQL query and url being the GraphQL endpoint.
@ResponseBody(dto: ClassConstructor, options?: ClassTransformOptions): Specifies the response DTO using a class
constructor and options from the class-transformer library.
@PathVariable(name?: string): Specifies the path variable, requiring the name of the variable.
@RequestParam(key?: string, defaultValue?: string): Specifies the query string parameter, requiring the key of the
parameter. If key is not specified, the parameter must be an object. See examples below:
request(@RequestParam('foo') query: string): stringrequest(@RequestParam() query: { foo: string }): string@RequestHeader(key?: string, option?: { defaultValue?: string; transform?: (value: string) => string }): Specifies
the request header, requiring the key of the header optionally.
@Bearer(): Specifies the bearer token using the Authorization header.
@Cookie(key: string): Specifies the cookie using the Cookie header, requiring the key of the cookie.
@RequestBody(key?: string, defalutValue?: unkown): Specifies the request body using application/json as the
content type, requiring the key of the body optionally.
@RequestForm(key?: string, defaultValue?: string): Specifies the request form
using application/x-www-form-urlencoded as the content type, requiring the key of the body optionally.
@CircuitBreaker(options?: CircuitBreaker.Options): Marks the method as a circuit breaker, with options being the
options of the circuit breaker. You can use global options by setting the circuitBreakerOption property in the module.
options is from opossum library.
@ResponseBody() from return type of exchange methodBecause of limitation of reflect-metadata, @ResponseBody() is required to specify the response DTO.
But this library provides a way to auto generate @ResponseBody() and infers response DTO from return type of exchange method.
It uses CLI Plugin like @nestjs/swagger and @nestjs/graphql.
To enable the plugin, open nest-cli.json
{
"compilerOptions": {
"plugins": ["@r2don/nest-http-interface"]
}
}
You can use the options property to customize the behavior of the plugin.
{
"compilerOptions": {
"plugins": [
{
"name": "@r2don/nest-http-interface",
"options": {
"interfaceFilenameSuffix": [".http.service.ts"]
}
}
]
}
}
Here is the list of options:
| option | default | description |
|---|---|---|
| interfaceFilenameSuffix | ['.service.ts'] | HTTP service files suffix |
@ResponseBody() will be added whenever nest start or nest build is executed.
This library is licensed under the MIT license.
To run tests, execute:
$ pnpm test
FAQs
HTTP client for Nest framework, inspired by HTTP interface in Spring 6
The npm package @r2don/nest-http-interface receives a total of 27 weekly downloads. As such, @r2don/nest-http-interface popularity was classified as not popular.
We found that @r2don/nest-http-interface demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?

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.

Security News
A Shai-Hulud infection exposed Suno's source code, which shows the AI music startup stream-ripped tracks to train its models.

Security News
Vercel is formalizing a monthly release program for Next.js. The change follows React2Shell and a sharp rise in AI-assisted vulnerability discovery.

Research
/Security News
11 malicious NuGet tools pose as game cheats to deploy Windows payloads, track hosts, and use Google Sheets for telemetry and control.