The browser is able to load static content via http by browsing to a resource, often it is necessary to
request additional data with javascript, this is where the fetch
API comes into
play
execute a fetch request with a specific HTTP method
Check if request was successfull (200)
Get the response body as text (also json, arrayBuffer, blob are supported)
Catch block to handle network errors
Prepare URL for post request
set http method
set request body
set additional headers to match content
check if request was true
handle network errors
The AbortController
offers a nice primitive to enable cancellation and could also be used in your own APIs
create new web socket connection
Add error callback
Add close callback
Add open callback
Send a message to the server
Add callback for messages
create new event source
listen to messages
listen to custom events