Giter VIP home page Giter VIP logo

Comments (5)

sindresorhus avatar sindresorhus commented on May 22, 2024

I think the error message is pretty clear and it's also documented in the readme, so I'm not really sure what this issue is about. It should be:

-const json = await api.post(`/connect`, {json: params}).json();
+const json = await api.post(`connect`, {json: params}).json();

from ky.

indatawetrust avatar indatawetrust commented on May 22, 2024

.

from ky.

lohfu avatar lohfu commented on May 22, 2024

@sindresorhus why was this behaviour implemented? ie why can the input not start with a / when using the prefix URL option?

i'm currently passing a fetch instance as the extra argument to my redux thunks to make testing and SSR easier... i am trying to move to ky and was hoping passing an extended version with a prefixUrl option would work, but since all my requests are made to /api/cars or similar they all fail.

from ky.

sindresorhus avatar sindresorhus commented on May 22, 2024

See #11

@sholladay Maybe we should include a reasoning for why it is like this in the prefixUrl docs?

from ky.

sholladay avatar sholladay commented on May 22, 2024

Yeah, we should document it. 👍

The discussion about it is pretty long but the important bits start around #11 (comment). I would summarize it like this:

  1. We want ky(input, { prefixUrl }) to be unambiguous in its semantics. Specifically, it does not follow the URL resolution algorithm. By restricting the allowed input, we're able to hopefully make this a little more clear and predictable.
  2. We want to enforce consistency. Having myApi('foo') in one place and myApi('/foo') in another place is confusing. Having a One True Way™ is nice in this case.
  3. The code to support any combination of optional slashes on input and prefixUrl would be more fussy and complicated. It sounds trivial, but there are notable edge cases that need to be handled specially due to how fetch() will resolve relative URLs. You can see evidence of this in some of the intermediate commits in #11 before we had finalized the algorithm. It's technically doable, but the complexity barely seems worth it to me.

from ky.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.