-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how to use it with JavaScript #57
Comments
I also trying with axios or fetch and having constatly cors error. |
I too am having the same problem! If someone manages to solve it, could you post the solution here? Here is my code in TypeScript: I too am having the same problem! If someone manages to solve it, could you post the solution here? Here is my code in TypeScript: public header = { |
Same problem here. Got the response in Rest Client in VScode when calling it from a .http file, but then when trying to do the same thing with javascript - the problem with cors appeared. |
You should not call the service directly. You must call the service through your own server |
@Raminmr how can i achieve that, let's say I'm running my server on http://localhost:3000 |
Which stack? With next you may use SSR |
const otrosParametros={ You should add this in the header, |
@vinibgoulart , regarding the password, I must create one? What password should I send? I have an error message: {status: 'error', message: 'User validation failed: password: Please provide y…rovide your email, name: Please provide your name'} |
@vinibgoulart im using qwik |
@notsag01 You already register? https://github.com/raminmr/free-api-worldcup2022#register You need to register an account before logging in |
@vinibgoulart , It won't let me register, it returns "error 400". Thanks all the same |
Hi guys i managed to do this. const axios = require('axios'); //u dont need to keep register bcs your using it only once, so make a call and get rid of that const config = { axios(config) //next you need to login to get token. You need to call this endpoint 1/24h(bcs every time you are logging in your token changes, your being loggedIn for 24hrs) and store token in some variable. const config = { axios(config) //teams const config = { axios(config) |
Bud
Thank you for taking the time to give such a detailed explanation. I'll try it tomorrow. |
and use a proxy from the client? |
Looks like you are calling API directly from the client side using React. If you also have a nodejs server running, call the football API from there. If you don't have your own server then create one with express. Create your own API endpoint and call the endpoint from there so that your express server further calls the football API. Basically, you are creating a proxy server. The CORS error will be resolved this way |
Solved for vite
|
Which folder will this code be |
thanks everyone for your help, this is the code that worked for me on Vite server
|
wait! u cannot directly use it with javascript because as the author states that we can fetch the API on "SERVER SIDE" only for that u can use popular javascript framework "NODE js" here how i solved .. => app.js (my server file)
=> in javascript file
THATS IT AND NOW U WILL GET OUTPUT IN THE CONSOLE... |
Hello, I have made my own API with NestJs consuming @Raminmr's API, I explain it on my YouTube channel |
Thanks @ayan-de |
i have been trying to change the cURL request to JavaScript with a fetch method however, it is not working
sample
fetch('http://api.cup2022.ir/api/v1/user/login', {method: 'POST',
headers: {
'Content-Type': 'application/json'
},body: JSON.stringify({
'email': 'XXXXXXXX.com',
'password': 'XXXXXXXXXX'
})})
The text was updated successfully, but these errors were encountered: