👉 Request Methods
A couple of methods are supported along with extra ones for more flexibility.
Z-fetch supports the common HTTP methods such as GET, POST, PUT, DELETE, and more.
💡 And making one can be as easy as:
And Here is the full list of supported methods:
- GET
- POST
- PUT
- DELETE
- PATCH
- HEAD
- OPTIONS
- TRACE
- CUSTOM
Heads Up!
All method names are uppercase to match the HTTP verbs that these methods represent. This is only not so for when using an instance where then it's instance.method eg. api.get('url');
Explanation
- Each request can be made separately or using an instance where it gets accessed as a property of that instance.
- Each request can take a URL and an optional options object.
- The options supports all native fetch options and some more z-fetch specific options.
- The Z-fetch specific options in this case are same as the create instance options just with some few unsupported ones on per request level such as hooks.
- Each request returns a result object containing the response
data
,error
, and the nativeresponse
object if you need more control over the response. - The request result also includes additional properties and methods for extra functionality such as refetching, canceling, and more.
- The separately used request or one used with an instance both take the same options and return the same result object.
Dev Note
Z-Fetch is 100% type safe, so expect some cool auto-completions from your IDE.
Request Examples
GET Request
POST Request
PUT Request
PATCH Request
DELETE Request
OPTIONS, TRACE, HEAD and CUSTOM Methods
OPTIONS Request
TRACE Request
HEAD Request
CUSTOM Request
More Advanced Features
Z-Fetch also exposes methods for polling, caching, request cancellation, and refetching:
Polling
Caching
Request Cancelling
Refetching
Direct Use of Fetch Options
You can use Z-Fetch as you would use the native fetch, with extra features:
🙋♂️ What else? Suggestions and feedback come in handy on the GitHub page. Please feel free to contribute or report any issues you encounter. This all was made by a human before vibe coding was a thing!