Skip to content

Commit

Permalink
docs: add custom client with angular client to guide (#1558)
Browse files Browse the repository at this point in the history
  • Loading branch information
soartec-lab authored Aug 2, 2024
1 parent b7d51f6 commit ccc4ff9
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions docs/src/pages/guides/custom-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,55 @@ export type BodyType<BodyData> = CamelCase<BodyType>;
```

Or, Please refer to the using custom fetch with Next.js sample app [here](https://github.com/orval-labs/orval/blob/master/samples/next-app-with-fetch/custom-fetch.ts).

#### Angular

Even if you use the `angular` client, you can add mutator functions to your configuration to set up your preferred HTTP client.

```js
module.exports = {
petstore: {
output: {
...
override: {
mutator: 'src/api/mutator/response-type.ts'
}
}
...
},
};
```

```ts
// response-type.ts

import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

const responseType = <Result>(
{
url,
method,
params,
data,
}: {
url: string;
method: string;
params?: any;
data?: any;
headers?: any;
},
http: HttpClient,
): Observable<Result> =>
http.request<Result>(method, url, {
params,
body: data,
responseType: 'json',
});

export default responseType;
```

Please also refer to sample app for more details.

https://github.com/orval-labs/orval/tree/master/samples/angular-app

0 comments on commit ccc4ff9

Please sign in to comment.