How to call an API from JavaScript #1035
-
I have two projects with .NET Aspire Orchestrator Support:
The From the static HTML I want to make a GET request to for example How can I make enable the orchestration to the API in the JavaScript? With |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Can you show what you were doing with tye? |
Beta Was this translation helpful? Give feedback.
-
I have a sample solution with HTMX + Minimal API:
name: markupolation
services:
- name: markupolation-sample-api
project: Markupolation.Sample.Api/Markupolation.Sample.Api.csproj
bindings:
- port: 5000
protocol: https
- name: markupolation-sample-htmx
project: Markupolation.Sample.Htmx/Markupolation.Sample.Htmx.csproj
bindings:
- port: 5001
protocol: https
ingress:
- name: ingress
bindings:
- port: 8080
protocol: https
rules:
- path: /api
service: markupolation-sample-api
- service: markupolation-sample-htmx
<article class="content px-4">
<!-- Lazy Loading -->
<div hx-get="/api/hello" hx-trigger="load"></div>
</article>
When browsing the site via the ingress, it works like a charm:
|
Beta Was this translation helpful? Give feedback.
You'd need to manually compose your app with a common ingress server (i.e. another ASP.NET Core project that uses YARP) if you want the frontend JS from one app to be able to request the API from another app on a common host name, and then browse to that ingress server's endpoint URL. From the browser's point of view, your app is coded so that all resources are on the same host so you'll need to ensure that's the actual case.