-
What I want to do:Making a call to the Twitter API directly from within a static Blazor WASM front-end client (the browser), so without calling a back-end API which makes a call to the Twitter API. The problemThe Twitter API (v1/v2) doesn't support CORS (yet, they say they are looking into it) they only support back-end (server to server) calls to the Twitter API. So the Twitter API doesn't add the
But with Blazor WASM I think it would be a good idea to make the calls directly to the Twitter API from within the client, so skipping the back-end API step, taking up less server resources, let the user's browser do the hard work. And yeah, this sure does scale 😉 Client/Auth SafetyTwitter API V2 does support a "Public Client" scenario to authenticate, where you only need to send your Client ID and no secret. You then can get an A Possible Solution?I've read at Stack Overflow that people use a reverse proxy to do this, so I directly thought about using YARP for this. I'd like to use YARP to do this:
Where I am nowI've read the YARP documentation, especially Direct Forwarding, Header Routing and Cross-Origin Requests and searched the YARP Q&A Discussions. It's a lot of information and I don't know exactly where to begin but I don't mind putting more effort and time learning in it. My Questions
Thank you, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi, yes this is possible to do with YARP.
As long as the browser can make an HTTP request to it, YARP doesn't care that it came from a Blazor browser app.
I would recommend you take a look at the minimal sample. The only modification you should need is to the config file. Your config may look something like "ReverseProxy": {
"Routes": {
"catchAllRoute": {
"ClusterId": "twitterCluster",
"Match": {
"Path": "{**catch-all}"
},
"Transforms": [
{
"ResponseHeader": "Access-Control-Allow-Origin",
"Set": "*"
}
]
}
},
"Clusters": {
"twitterCluster": {
"Destinations": {
"twitterV2": {
"Address": "https://api.twitter.com/2/"
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
Hi, yes this is possible to do with YARP.
As long as the browser can make an HTTP request to it, YARP doesn't care that it came from a Blazor browser app.
I would recommend you take a look at the minimal sample.
The only modification you should need is to the config file.
You must specify the correct destination, and add a Transform that adds the header.
Your config may look something like