공지사항

GitHub - Sindresorhus/ky: ???? Tiny & Elegant JavaScript hTTP Client B…

페이지 정보

profile_image
작성자 Maureen
댓글 0건 조회 11회 작성일 26-08-02 12:38

본문

7d2f2533-68fc-42ea-834b-496f1ccd9966Sindre's open supply work is supported by the neighborhood. Ky targets trendy browsers, Node.js, Bun, and Deno. It's only a tiny package with no dependencies. This readme is for the next version of Ky. For the current model, click here. If you're using Deno, import Ky from a URL. The input and choices are the same as fetch, with further options out there (see beneath). Returns a Response object with Body strategies added for convenience. So you may, for example, call ky.get(enter).json() directly with out having to await the Response first. When referred to as like that, an appropriate Accept header can be set depending on the body technique used. Available physique shortcuts: .json(), .textual content(), .formData(), .arrayBuffer(), .blob(), and .bytes(). The .bytes() shortcut is just present when the runtime supports Response.prototype.bytes(). ⌨️ TypeScript: Accepts an elective type parameter, which defaults to unknown, and is handed via to the return sort of .json(). This throws a SchemaValidationError when validation fails. Sets options.technique to the strategy name and makes a request.


⌨️ TypeScript: Accepts an optionally available type parameter for use with JSON responses (see ky()). Same as fetch input. When utilizing a Request occasion as input, any URL altering options (corresponding to baseUrl) can be ignored. HTTP methodology used to make the request. Internally, the standard methods (GET, Post, PUT, PATCH, HEAD, DELETE, and Query) are uppercased as a way to avoid server errors due to case sensitivity. Shortcut for sending JSON. Use this instead of the physique choice. Accepts any plain object or worth, which will probably be stringified utilizing JSON.stringify() and despatched in the body with the right header set. Search parameters to include in the request URL. Setting this may merge with any existing search parameters in the enter URL. Accepts any value supported by URLSearchParams(). When passing an object, setting a value to undefined deletes the parameter, whereas null values are preserved and converted to the string 'null'. A base URL to resolve the enter towards. When the enter (after making use of the prefix possibility) is only a relative URL, equivalent to 'customers', '/customers', or '//my-site.com', will probably be resolved against the baseUrl to find out the vacation spot of the request.


Otherwise, the input is absolute, such as 'https://my-site.com', and it'll bypass the baseUrl. Useful when used with ky.extend() to create niche-particular Ky situations. If the baseUrl itself is relative, it is going to be resolved towards the atmosphere's base URL, such as doc.baseURI in browsers or location.href in Deno (see the --location flag). Tip: When setting a baseUrl that has a path, we recommend that it embrace a trailing slash /, as in '/api/' slightly than /api. This ensures extra intuitive habits for stress page-relative input URLs, reminiscent of 'customers' or './customers', where they'll lengthen from the total path of the baseUrl somewhat than changing its final path section. A prefix to prepend to the input before making the request (and before it's resolved in opposition to the baseUrl). It may be any legitimate path or URL, either relative or absolute. A trailing slash / is optionally available and might be added robotically, if wanted, when it's joined with enter. Only takes impact when enter is a string.


851d391ab9ba598c358eecf7add3033b.webpUseful when used with ky.extend() to create area of interest-specific Ky instances. In most cases, it's best to use the baseUrl option as a substitute, as it's extra per net standards. However, prefix is helpful if you want origin-relative enter URLs, similar to /users, to be treated as in the event that they had been page-relative. In different phrases, the main slash of the enter will essentially be ignored, as a result of the prefix will develop into a part of the enter before URL decision happens. The prefix and input are joined with a slash /, and slashes are normalized at the be part of boundary by trimming trailing slashes from prefix and leading slashes from enter. After prefix and input are joined, the result's resolved against the baseUrl option, if present. Controls retry behavior. Each subject is documented individually beneath. If retry is a quantity, it will likely be used as restrict and different defaults will stay in place. Network errors (e.g., DNS failures, connection refused, offline) are automatically retried for retriable methods.


Only errors recognized as community errors are retried; different errors (e.g., programming bugs) are thrown instantly. Use shouldRetry to customise this habits. 413 Payload Too Large is only retried when the response includes a retry timing header. When the response status is contained in each statusCodes and afterStatusCodes, Ky uses retry timing headers to decide on the retry delay. Retry-After may provide a delay in seconds or an HTTP-date. If Retry-After is lacking, Ky falls again to fee-restrict timing headers (RateLimit-Reset, X-RateLimit-Retry-After, X-RateLimit-Reset, and X-Rate-Limit-Reset). Numeric Retry-After and X-RateLimit-Retry-After values are interpreted as delay seconds. Numeric RateLimit-Reset, X-RateLimit-Reset, and X-Rate-Limit-Reset values may also be interpreted as present-period Unix timestamps. If the status code isn't in afterStatusCodes, retry timing headers will be ignored. If the retry delay from a retry timing header is higher than maxRetryAfter, Ky will use maxRetryAfter. The backoffLimit option is the upper restrict of the delay per retry in milliseconds.

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입