> For the complete documentation index, see [llms.txt](https://jakekwak.gitbook.io/nestjs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jakekwak.gitbook.io/nestjs/faq/untitled.md).

# HTTP adapter

## HTTP adapter

경우에 따라 Nest 애플리케이션 컨텍스트 내에서 또는 외부에서 기본 HTTP 서버에 액세스할 수 있습니다.

기본적으로 모든 고유 (플랫폼 별) HTTP 서버/라이브러리 인스턴스는 **어댑터**로 래핑됩니다. 어댑터는 응용 프로그램 컨텍스트에서 가져 와서 다른 공급자에게 쉽게 주입할 수 있는 전역적으로 사용 가능한 공급자로 등록되어 있습니다.

## Outside strategy

애플리케이션 컨텍스트 외부에서 `HttpAdapter`를 가져 오기 위해 `getHttpAdapter()`메소드를 호출할 수 있습니다.

```typescript
@@filename()
const app = await NestFactory.create(ApplicationModule);
const httpAdapter = app.getHttpAdapter();
```

## In-context strategy

애플리케이션 컨텍스트 내에서 `HttpAdapterHost`를 가져 오려면 기존의 다른 제공자와 동일한 방식으로 ( constructor를 통해) 주입할 수 있습니다.

```typescript
@@filename()
export class CatsService {
  constructor(private readonly adapterHost: HttpAdapterHost) {}
}
@@switch
@Dependencies(HttpAdapterHost)
export class CatsService {
  constructor(adapterHost) {
    this.adapterHost = adapterHost;
  }
}
```

> info **힌트** `HttpAdapterHost`는 `@nestjs/core` 패키지에서 가져옵니다.

## Adapter host

지금까지 우리는 `HttpAdapterHost`를 얻는 방법을 배웠다. 그러나 여전히 실제 'HttpAdapter'는 아닙니다. `HttpAdapter`를 얻으려면 간단히 `httpAdapter` 속성에 액세스하십시오.

```typescript
const adapterHost = app.get(HttpAdapterHost);
const httpAdapter = adapterHost.httpAdapter;
```

`httpAdapter`는 프레임 워크가 사용하는 HTTP 어댑터의 실제 인스턴스입니다. `ExpressAdapter` 또는 `FastifyAdapter`가 될 수 있습니다 (두 클래스 모두 `AbstractHttpAdapter`를 확장함).

모든 어댑터는 HTTP 서버와 상호 작용할 수 있는 몇가지 유용한 방법을 제공합니다. 그럼에도 불구하고 라이브러리 참조에 직접 액세스하려면 `getInstance()` 메소드를 호출하십시오.

```typescript
const instance = httpAdapter.getInstance();
```
