First, here is a list of things I've wanted in an internet library API over the years.
- Send any type of HTTP request. HEAD is the obvious one missing from libURL. PATCH is also missing but I've never had to use that myself.
- Define status callbacks on a per-request basis. Any request with a callback becomes asynchronous.
- If a callback is defined, all progress and completion information is sent to the defined callback. All error reporting is sent to the callback as well, not in the result right after the call.
- Define headers on a per-request basis. No global httpHeaders property.
- Allow the developer to associate an id with a request so that it can be associated with other data structures in callbacks. Sometimes the URL being used is the exact same for multiple requests and the only thing that changes is the data being sent along with the request.
- Each request should be identified using a unique id rather than the URL itself. No errors about a url already being loaded.
I've been thinking about syntax for interacting with a server and here is what I like the most so far:
Code: Select all
send [METHOD] request to url [URL] [with headers HEADERS] [with data DATA] [with callback CALLBACK] [with id ID]
Code: Select all
-- Synchronous call which defaults to GET
send request to url tURL
-- Asynchronous GET request
send GET request to url tURL with callback "MyCallback"
-- Synchronous PUT request with custom headers and data sent to the server.
send PUT request to url tURL with headers tHeaders with data tData
-- Asynchronous POST request with custom headers and data sent to the server.
send POST request to url tURL with data tData with callback "MyCallback"
-- Async HEAD request
send HEAD request to url tURL with callback "MyCallback"
-- Async DELETE request
send DELETE request to url tURL with callback "MyCallback"
-- Pass along a parameter that associates this request with something in our app
-- Also group the URLs using different callbacks.
send GET request to URL tURL1 with callback "CallbackCategory1" with id 2500
send GET request to URL tURL2 with callback "CallbackCategory1" with id 2501
send GET request to URL tURL3 with callback "CallbackCategory2"