kit icon indicating copy to clipboard operation
kit copied to clipboard

consume external REST api inside a component

Open Kokoserver opened this issue 3 years ago • 1 comments

Describe the problem

I think one the reason why developers love sveltekit, is how you can just connect your backend quickly without any hassle of installing packages for routing, now even calling google.com will throw a cors errors. imagine consuming an ecommerce API, that means i have to create endpoint for all of them which for me is a double work and even redundancy there should be way. Now to achieve just getting a data from server one will have to send request from components to endpoint then from endpoint to api i think that just very bad and if sveltekit will want fullstack only then is better a routing library is created for svelte. Screenshot 2022-09-20 191507

Describe the proposed solution

A question on setting up asking if there is an external server

Alternatives considered

if tried form actions as a proxy and the response status is not 200 the server will throw 500 error with the attached erros
Screenshot 2022-09-20 144101

Importance

would make my life easier

Additional Information

Kokoserver avatar Sep 20 '22 18:09 Kokoserver

I don't know what this issue is actually requesting, and I don't know what different code would be generated during create-svelte is you said you did want to use an external API.

You can make requests to external services in +page.server.js if you want to sidestep certain CORS issues.

If the issue is about a confusing error at runtime when setting up a proxy, please open an issue for that with a minimal reproduction.

Conduitry avatar Sep 20 '22 18:09 Conduitry

Closing as no clarification about the feature request was given.

Regarding "even Google gives CORS error" - that is not solvable on our side, since Google doesn't set the headers which would allow you to fetch it from the browser. As Conduitry pointed out, going through +page.server.js is the way to go here.

dummdidumm avatar Jan 10 '23 13:01 dummdidumm

Thanks you I tried it now it works well. Congrats on version 1.0 release well done team svelte

Kokoserver avatar Jan 11 '23 13:01 Kokoserver