Cocoa + HTTP
http://you.down.wi.th/rpc?you=know+me

       Jonathan ‘Wolf’ Rentzsch
           http://rentzsch.com
       ...
HTTP
• Not just “Hypertext”: general transport protocol
  • simple
  • efficient (binary-clean)
  • widespread
  • extensi...
Downsides
• Not really connection-oriented (stateless)
 • work-arounds: cookies, Comet
• GET vs POST vs REST
 • “Represent...
Client-side
• curl
• Core Foundation
• NSURLHandle (CURLHandle)
• DDCurl
• NSURLConnection (NSURLRequest+postForm)
• Pytho...
Server-side
• CFHTTP
• JRHTTPServer
• ToxicHTTP
• TouchHTTPD
• Apple’s CocoaHTTPServer
• Cultured Code’s SimpleHTTPServer
...
RPC with GET
• GET (URL-encoded query string)
  http://example.com/action.php?foo=bar

• “URL-encoded” == percent-escaping...
GET On-the-wire
• GET /action.php?foo=bar HTTP/1.1
  HOST: example.com


• HTTP/1.1 200 Ok
  ...




                     ...
RPC with POST
• Like GET, but places parameters into HTTP body
• Large payloads (upload gigs of data)
• Choice of encoding...
POST On-the-wire
• GET /action.php HTTP/1.1
  HOST: example.com
  Content-Type: application/x-www-form-urlencoded

  foo=b...
POST On-the-wire
• GET /action.php HTTP/1.1
  HOST: example.com
  Content-Type: multipart/form-data; boundary=XXX

  --XXX...
RPC with REST
• Leverages Standard HTTP Methods
  • POST => Create
  • PUT => Update
  • DELETE => Delete
• POST to http:/...
REST On-the-wire
• POST example.com
        /widgets HTTP/1.1
  Host:

  <?xml version=quot;1.0quot;?>
  <widget>
    <nam...
REST On-the-wire
• PUT /widgets/42 HTTP/1.1
  Host: example.com

  <?xml version=quot;1.0quot;?>
  <widget>
    <name>wilm...
REST On-the-wire
• DELETE /widgets/42 HTTP/1.1
  Host: example.com

• HTTP/1.1 200 Ok
  ...




                      Red ...
demo



Red Shed Software
 better necessarily means different
Upcoming SlideShare
Loading in …5
×

Cocoa + HTTP

4,901 views

Published on

intro to client+server HTTP tech for Cocoa coders

Published in: Technology, Design
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,901
On SlideShare
0
From Embeds
0
Number of Embeds
29
Actions
Shares
0
Downloads
36
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Cocoa + HTTP

  1. 1. Cocoa + HTTP http://you.down.wi.th/rpc?you=know+me Jonathan ‘Wolf’ Rentzsch http://rentzsch.com PSIG 115 Red Shed Software better necessarily means different
  2. 2. HTTP • Not just “Hypertext”: general transport protocol • simple • efficient (binary-clean) • widespread • extensible • standard authentication, crypto, RPC, unicode, etc Red Shed Software better necessarily means different
  3. 3. Downsides • Not really connection-oriented (stateless) • work-arounds: cookies, Comet • GET vs POST vs REST • “Representational State Transferquot; • URL-encoding vs Form-data (MIME); XML vs JSON • BEEP would andgreat butcomplicated as be it’s not nearly widespread is more Red Shed Software better necessarily means different
  4. 4. Client-side • curl • Core Foundation • NSURLHandle (CURLHandle) • DDCurl • NSURLConnection (NSURLRequest+postForm) • Python, Ruby, etc Red Shed Software better necessarily means different
  5. 5. Server-side • CFHTTP • JRHTTPServer • ToxicHTTP • TouchHTTPD • Apple’s CocoaHTTPServer • Cultured Code’s SimpleHTTPServer • Deusty Designs’ CocoaHTTPServer (auth, ssl) Red Shed Software better necessarily means different
  6. 6. RPC with GET • GET (URL-encoded query string) http://example.com/action.php?foo=bar • “URL-encoded” == percent-escaping http://example.com/action.php?foo=bar%20baz http://example.com/action.php?foo=bar+baz Red Shed Software better necessarily means different
  7. 7. GET On-the-wire • GET /action.php?foo=bar HTTP/1.1 HOST: example.com • HTTP/1.1 200 Ok ... Red Shed Software better necessarily means different
  8. 8. RPC with POST • Like GET, but places parameters into HTTP body • Large payloads (upload gigs of data) • Choice of encoding of parameters • URL-encoded (percent-encoding like GET) • Form-data (MIME stuff) Red Shed Software better necessarily means different
  9. 9. POST On-the-wire • GET /action.php HTTP/1.1 HOST: example.com Content-Type: application/x-www-form-urlencoded foo=bar%20baz • HTTP/1.1 200 Ok ... Red Shed Software better necessarily means different
  10. 10. POST On-the-wire • GET /action.php HTTP/1.1 HOST: example.com Content-Type: multipart/form-data; boundary=XXX --XXX Content-Disposition: form-data; name=quot;fooquot; Content-Type: text/plain; charset=utf-8 bar --XXX-- Red Shed Software better necessarily means different
  11. 11. RPC with REST • Leverages Standard HTTP Methods • POST => Create • PUT => Update • DELETE => Delete • POST to http://example.com/widgets • PUT to http://example.com/widgets/42 • DELETE http://example.com/widgets/42 Red Shed Software better necessarily means different
  12. 12. REST On-the-wire • POST example.com /widgets HTTP/1.1 Host: <?xml version=quot;1.0quot;?> <widget> <name>fred</name> </widget> • HTTP/1.1 201 Created ... Location: /widgets/42 Red Shed Software better necessarily means different
  13. 13. REST On-the-wire • PUT /widgets/42 HTTP/1.1 Host: example.com <?xml version=quot;1.0quot;?> <widget> <name>wilma</name> </widget> • HTTP/1.1 200 Ok ... Red Shed Software better necessarily means different
  14. 14. REST On-the-wire • DELETE /widgets/42 HTTP/1.1 Host: example.com • HTTP/1.1 200 Ok ... Red Shed Software better necessarily means different
  15. 15. demo Red Shed Software better necessarily means different

×