Add URLSession helpers to send request and parse response #38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a URLSession helper function to send requests, including their body, which is not possible for now because
WPNetworkRequest
don't have abody
property yet.Background URLSession
Due to the constraint on background URLSession instances where they can only get HTTP responses via
URLSessionDelegate
(thedataTask(for:completionHandler:)
and similar APIs would simply crash), we have to implement a custom delegate to get them work with ourasync
or closure-based APIs. This should work fine for now, but if in the future we want to accept background URLSession instances created by the clients, we should rethink this specialURLSessionDelegate
implementation.Error handling
This PR only includes a very light error handling. And the API-level (i.e. parsing
code
andmessage
from .org REST API response) error handling will wait once we have a solution on #22.