

Got is maintained by the same people as Ky. title ) //=> 'delectus aut autem How is it different from got import ky from '' const json = await ky ( '' ). For example, logging client activity to the server. In general, we recommend throwing an error instead of returning this symbol, as that will cause Ky to abort and then throw, which avoids these limitations.Ī valid use-case for ky.stop is to prevent retries when making requests for side effects, where the returned data is not important. text(), because there is no response to parse. It is also incompatible with body methods, such as. Be sure to check for a response before accessing any properties on it or use optional chaining. Note: Returning this symbol makes Ky abort and return with an undefined response. This will also short circuit the remaining beforeRetry hooks. Import ky from 'ky' // On const response = await ky ( 'unicorn', ) //=> '' defaultOptionsĪ Symbol that can be returned by a beforeRetry hook to stop the retry. Useful when used with ky.extend() to create niche-specific Ky-instances. The input argument cannot start with a slash / when using this option. Only takes effect when input is a string. A trailing slash / is optional and will be added automatically, if needed, when it is joined with input. It can be any valid URL, either relative or absolute. prefixUrlĪ prefix to prepend to the input URL when making the request. Setting this will override all existing search parameters in the input URL.Īccepts any value supported by URLSearchParams(). Search parameters to include in the request URL. Type: string | object | Array> | URLSearchParams Accepts any plain object or value, which will be JSON.stringify()'d and sent in the body with the correct header set. Type: object and any other value accepted by JSON.stringify() Internally, the standard methods ( GET, POST, PUT, PATCH, HEAD and DELETE) are uppercased in order to avoid server errors due to case sensitivity. When using a Request instance as input, any URL altering options (such as prefixUrl) will be ignored. Sets thod to the method name and makes a request. ky.get(input, options?) ky.post(input, options?) ky.put(input, options?) ky.patch(input, options?) ky.head(input, options?) ky.delete(input, options?) json() will return an empty string if body is empty or the response status is 204 instead of throwing a parse error due to an empty body. Unlike the Body methods of window.Fetch these will throw an HTTPError if the response status is not in the range of 200.299. When called like that, an appropriate Accept header will be set depending on the body method used. So you can, for example, call ky.get(input).json() directly without having to await the Response first. Returns a Response object with Body methods added for convenience. The credentials option is same-origin by default, which is the default in the spec too, but not all browsers have caught up yet.

The input and options are the same as fetch, with some exceptions: Import ky from '' API ky(input, options?)
