SweetURLRequest
SweetURLRequest simplifies common cases for creating an URLRequest and handling HTTPURLResponse.
Extensions for URLRequest:
⚡ Constants for HTTP methods
⚡ Properties to set common HTTP headers
⚡ URL/Form/JSON encoded parameters
Extensions for HTTPURLResponse:
⚡ Check for a 2xx success status code
⚡ Handle HTTP status codes via switch/case
⚡ Error enum for HTTP status codes
Examples
Example project
MetMuseumEndpoints: A Swift package for the The Metropolitan Museum of Art Collection API
Constants for HTTP methods
Properties to set common HTTP headers
URL/Form/JSON encoded parameters
Parameters will be URL-encoded for GET/HEAD/DELETE and sent as application/x-www-form-urlencoded body for other methods by default:
You can also pass a JSON body, this will use JSONEncoder to serialize the given data and set an appropriate Content-Type header: