This repository has been archived by the owner on Aug 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Elevate::HTTP Examples
Matt Green edited this page Jul 12, 2013
·
1 revision
Elevate's HTTP client differs a bit from other RubyMotion HTTP clients. Here's a short cookbook of examples to get you going.
Elevate returns the response synchronously, so you don't need to pass a block. The returned Response
object has accessors for all of the usual HTTP fields of interest: headers
, url
, and so forth. The body
field deserves special mention: if the Content-Type
of the request is application/json
, it will be automatically the decoded. Otherwise, it returns the raw request bytes as an instance of NSData
.
response = Elevate::HTTP.get("https://www.google.com/")
response = Elevate::HTTP.get("https://example.com/list", query: { q: "search_term" })
response = Elevate::HTTP.get("https://example.com/list", headers: { "API-Key" => "1234567890" })
response = Elevate::HTTP.post("https://example.com/register", form: { name: "matt", password: "secret" })
response = Elevate::HTTP.post("https://example.com/register", json: { name: "matt", password: "secret"})
credentials = { username: "matt", password: "secret" }
response = Elevate::HTTP.post("https://example.com/", credentials: credentials, json: { last_access: nil })
Credentials are not encrypted in transit, use HTTPS!