You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For development-time convenience, you can also pass the string `"https://*:*"` in the `allowed_outbound_hosts` collection. This allows the Wasm module to make HTTP requests to _any_ host and on any port. However, once you've determined which hosts your code needs, you should remove this string and list the hosts instead. Other Spin implementations may restrict host access and disallow components that ask to connect to anything and everything!
179
181
180
-
###Making HTTP Requests Within an Application
182
+
## Making HTTP Requests Within an Application
181
183
182
-
In an HTTP component, you can make requests to a path to make HTTP requests **within the current Spin application**. For example, if you make an outbound HTTP request to /api/customers/, Spin replaces self with whatever host the application is running on. It also replaces the URL scheme (`http` or `https`) with the scheme of the current HTTP request. For example, if the application is running in the cloud, Spin changes `/api`to `https://.../api`.
184
+
If your Spin application functions as a set of microservices, you'll often want to make requests directly from one component to another within the same application. It's best not to use a full URL for this, because that's not portable across different deployment environments - the URL in the cloud is different from the one in your development environment. Instead, Spin provides two ways to make inter-component requests:
183
185
184
-
Using paths means that the application doesn't need to know the URL where it's deployed, or whether it's running locally versus in the cloud.
186
+
* By component ID ("local service chaining")
187
+
* By route
185
188
186
-
> This doesn't work in Redis components because Spin uses the incoming HTTP request to determine the current host.
189
+
Both of these work only from HTTP components. That is, if you want to make an intra-application request from, say, a Redis trigger, you must use a full URL.
190
+
191
+
### Local Service Chaining
192
+
193
+
To make an HTTP request to another component in your application, use the special `<component-id>.spin.internal` host name. For example, an outbound HTTP request to `authz.spin.internal` will be handled by the `authz` component.
194
+
195
+
In this way of doing self-requests, the request is passed in memory without ever leaving the Spin host process. This is extremely fast, as the two components are wired almost directly together, but may reduce deployment flexibility depending on the nature of the microservices. Also, components that are the target of service chaining requests may see URLs in both routed and chained forms: therefore, if they parse the URL (for example, extracting a resource identifier from the path), they must ensure both forms are correctly handled.
196
+
197
+
You must still grant permission by including the relevant `spin.internal` hosts in `allowed_outbound_hosts`:
To allow local chaining to _any_ component in your application, use a subdomain wildcard:
204
+
205
+
```toml
206
+
allowed_outbound_hosts = ["*://*.spin.internal"]
207
+
```
208
+
209
+
> Local service chaining is not currently supported on Fermyon Cloud.
210
+
211
+
### Intra-Application HTTP Requests by Route
212
+
213
+
To make an HTTP request to another route with your application, you can pass just the route as the URL. For example, if you make an outbound HTTP request to `/api/customers/`, Spin prepends the route with whatever host the application is running on. It also replaces the URL scheme (`http` or `https`) with the scheme of the current HTTP request. For example, if the application is running in the cloud, Spin changes `/api` to `https://.../api`.
214
+
215
+
In this way of doing self-requests, the request undergoes normal HTTP processing once Spin has prepended the host. For example, in a cloud deployment, the request passes through the network, and potentially back in through a load balancer or other gateway. The benefit of this is that it allows load to be distributed across the environment, but it may count against your use of bandwidth.
187
216
188
217
You must still grant permission by including `self` in `allowed_outbound_hosts`:
0 commit comments