Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why name endpoints in sveltekit .json.js?

I’ve seen naming endpoints in sveltekit with .json.js. Why? .js should be enough, right?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

It’s an old convention from earlier days to double the extension with the format of the returned data (data.json.js, data.xml.js) but is no longer used. I believe before it would even put the correct headers based on the extension, but think that is no longer the case.

You can of course still do this to make it clear to consumers what they will get back:

// I know I will get a json object from this because it says so in the name
const res = await fetch('something/products.json'); 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading