Skip to content

Commit 2628e59

Browse files
committed
docs: update README.md
1 parent e2eeb1f commit 2628e59

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

README.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<a href="http://nestjs.com"><img src="https://nestjs.com/img/logo_text.svg" alt="Nest Logo" width="320" /></a>
2+
<a href="https://nestjs.com"><img src="https://nestjs.com/img/logo_text.svg" alt="Nest Logo" width="320" /></a>
33
</p>
44

55
# nest-http-interface
@@ -39,7 +39,7 @@ import {Module} from '@nestjs/common';
3939
import {HttpInterfaceModule} from '@r2don/nest-http-interface';
4040

4141
@Module({
42-
imports: [HttpInterfaceModule.register()],
42+
imports: [HttpInterfaceModule.forRoot()],
4343
})
4444
export class AppModule {
4545
}
@@ -48,13 +48,13 @@ export class AppModule {
4848
Then, you need to create the desired HTTP service and specify several decorators:
4949

5050
```ts
51-
import {HttpInterface, GetExchange, ResponseBody, imitation} from '@r2don/nest-http-interface';
51+
import {HttpInterface, GetExchange, ResponseBody, imitation, PathVariable} from '@r2don/nest-http-interface';
5252

53-
@HttpInterface()
54-
class SampleClient {
55-
@GetExchange('https://example.com/api') // path or full url
56-
@ResponseBody(ResponseTest) // response dto
57-
async request(): Promise<ResponseTest> {
53+
@HttpInterface('https://example.com/api') // base url
54+
class UserHttpService {
55+
@GetExchange('/users/{id}') // path
56+
@ResponseBody(UserResponse) // response dto
57+
async request(@PathVariable() id: number): Promise<UserResponse> {
5858
return imitation(); // this is a mock function to prevent the type error
5959
}
6060
}
@@ -64,15 +64,14 @@ After adding the service to the providers in the module, you can use it and make
6464
the `request` method:
6565

6666
```ts
67-
import {Module} from '@nestjs/common';
68-
import {HttpInterfaceModule} from '@r2don/http-interface';
69-
import {SampleClient} from './sample.client';
67+
@Injectable()
68+
class UserService {
69+
constructor(private readonly client: UserHttpService) {
70+
}
7071

71-
@Module({
72-
imports: [HttpInterfaceModule.register()],
73-
providers: [SampleClient]
74-
})
75-
export class AppModule {
72+
async getUser(id: number): Promise<UserResponse> {
73+
return this.client.request(id);
74+
}
7675
}
7776
```
7877

0 commit comments

Comments
 (0)