---
schema_version: "1"
id: d5f4ab4222df448fb553bec9256c836b6b02c0ddca3c7bd9bc7b2697ae5027f3
title: Performing an HTTP Call
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/pdk/1.6/policies-pdk-configure-features-http-request.md
canonical_url: https://docs.mulesoft.com/pdk/1.6/policies-pdk-configure-features-http-request
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 8d121ece2ea20ccd1b32751ccf421b27f3d84ad9870c1b3f8b103b1bce0e968f
description: MuleSoft Documentation Site
release: "1.6"
latest: false
---
---
product: Omni Gateway Policy Development Kit (PDK)
version: 1.6
---

# Performing an HTTP Call

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

> [!NOTE] To view an example policy project that makes HTTP calls, see
> [Simple OAuth 2.0 Validation Policy Example](https://github.com/mulesoft/pdk-custom-policy-examples/blob/1.6.0/simple-oauth-2-validation/README.md).

To interact with external services, a policy can use HTTP calls. You can only make HTTP calls from
the request filter or the response filter.

## Define the HTTP Service

Define your service as a parameter in your schema definition to make HTTP requests. To learn more
about defining parameters, see
[Defining a Policy Schema Definition](https://docs.mulesoft.com/pdk/1.6/policies-pdk-create-schema-definition)

The following code snippet provides an example schema definition for an external service:

```yaml
properties:
  externalService:
    type: string
    format: service
  endpointPath:
    type: string
```

In the policy’s Rust source code, you can access the defined external service in the `Config`
struct. To perform requests, call the HTTP client in your policy, for example:

```rust
let response = client
    .request(&config.external_service)
    .path(&config.endpoint_path)
    .headers(vec![("Content-Type", "application/json")])
    .body(r#"{"key": "value"}"#.as_bytes())
    .put().await?;
```

## Inject the HTTP Client Parameters to Enable Requests

To perform an HTTP call, either inject the `HTTPClient` into the `[entrypoint]` function or the
wrapper functions:

- To enable requests in the request and response filters, inject the client parameter into the
  `#[entrypoint]` function:

  ```Rust
  #[entrypoint]
  async fn configure(launcher: Launcher, Configuration(bytes): Configuration, client: HttpClient) -> Result<()> {
      let config: Config = serde_json::from_slice(&bytes).unwrap();

      // Both request and the response handlers will use the client
      let filter = on_request(|request_state| request_filter(request_state, &config, &client))
          .on_response(|response_state, request_data| {
              response_filter(response_state, request_data, &config, &client)
          });

      launcher.launch(filter).await?;
      Ok(())
  }
  ```

- To enable requests only in the request or the response, inject the client parameters either in the
  `on_request` or `on_response` wrapper functions:

  ```Rust
  // Handler with the logic for incoming requests
  ​​async fn request_filter(state: RequestState, conf: &Config, client: HttpClient) {
   ...
  }

  #[entrypoint]
  async fn configure(launcher: Launcher, Configuration(bytes): Configuration) -> Result<()> {
      let config: Config = serde_json::from_slice(&bytes).unwrap();

      // For incoming request events, using the on_request wrapper, inject the client and pass it to the request_filter handler
      launcher
          .launch(on_request(|request, client| {
              request_filter(request, &config, client)
          }))
          .await?;
      Ok(())
  }
  ```

## See Also

- [Implementing Your Custom Policy Features in Rust](https://docs.mulesoft.com/pdk/1.6/policies-pdk-configure-features)
