Getting Started
Note: Petitio supports both require
and import
syntax out of the box, so
there's no need to do any pesky ESM or CJS hacks.
#
Basic UsageThe default export of Petitio is a wrapper function for PetitioRequest, meaning all you need to get started is as follows:
That instantiates a PetitioRequest for example.com
. Simple right?
Let's take a look at how we send requests and work with responses.
Fast and clean. Beautiful, even. But how does that work? PetitioRequest#send instructs Petitio to send the current PetitioRequest and returns a PetitioResponse with the response data, and then PetitioResponse#text parses the response body from a buffer to a string. The shorthand form of this is PetitioRequest#text, which sends the request and invokes text parsing for you in one call.
That's the basics covered! Check out some more usage examples, or read through our other guides.