Your SlideShare is downloading. ×
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Web Services with Objective-C
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Web Services with Objective-C

36,461

Published on

Intro to writing web services clients in Objective-C

Intro to writing web services clients in Objective-C

Published in: Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
36,461
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
460
Comments
0
Likes
8
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. [email_address]
  • 2. Hot New Technology
    • World Wide Web – WWW
    • Web 3.0
    • Rise of the Machines!!!
    [email_address]
  • 3. Web services
    • Web services – Websites for programs
    [email_address]
  • 4. Common Web Services
    • Flickr
    • Amazon
    • Twitter
    • Youtube
    • Ebay
    • Google search, maps, etc.
    • Meetup
    • Thousands of others
    [email_address]
  • 5. 2 basic styles of services
    • Service Oriented Architectures – (Distributed Objects)
    • CORBA, SOAP, XML-RPC, COM
    • Resource Oriented Architectures
      • Resources can be anything
      • REST – use simple web based technologies
        • HTTP
        • URI
        • XML (or Json, xhtml, text, plists, etc.)
    [email_address]
  • 6. HTTP
    • Methods: GET, POST, PUT, DELETE, HEAD
    • Parameters in URL or Body
    • Return codes: 200, 404, 500, etc.
    • Headers: Cache, Authentication, etc.
    [email_address]
  • 7. URI / URL
    • Addressability
    • Connectedness
    • Uniformity
    • Hierarchical
    [email_address]
  • 8. Content
    • Format up to the designer
    • XML
    • JSON – especially for AJAX
    • XHTML
    • Can support multiple formats
    [email_address]
  • 9. Steps for using a RESTful service
    • Gather information - URI, Method, Params
    • Make HTTP Request
    • Parse Result
    [email_address]
  • 10. 1) Gather information
    • Study the API
      • http://www.meetup.com/meetup_api/docs/
    • Decide what you want to do: Ie. Get a list of meetups near me.
      • http://api.meetup.com/events.xml/?lat=40.743348&lon=-73.993525&radius=1&key=123
    [email_address]
  • 11. Result (part 1)
    • <results>
    • <head>
    • <count>200</count>
    • <total_count>1274</total_count>
    • <updated>Mon Aug 25 20:10:21 EDT 2008</updated>
    • <description>API method for accessing meetup events</description>
    • <lat>40.743348</lat>
    • <id/>
    • <method>Events</method>
    • <lon>-73.993525</lon>
    • <title>Meetup Events</title>
    • <next>
    • http://api.meetup.com/events/ ?...
    • </next>
    • <link>http://api.meetup.com/events/</link>
    • <url>
    • http://api.meetup.com/events/ ? …
    • </url>
    • </head>
    [email_address]
  • 12. Result (part 2)
    • <items>
    • <item>
    • <lon>-73.98999786376953</lon>
    • <rsvpcount>3</rsvpcount>
    • <group_name>Better Laugh Laughter Yoga</group_name>
    • <lat>40.7400016784668</lat>
    • <feecurrency>USD</feecurrency>
    • <time>Mon Aug 25 19:30:00 EDT 2008</time>
    • <event_url>http://stress.meetup.com/12/calendar/8385325</event_url>
    • <attendee_count>0</attendee_count>
    • <id>8385325</id>
    • <venue_lon/>
    • <fee>0.0</fee>
    • <venue_name/>
    • <venue_lat/>
    • <description/>
    • <photo_url>
    • http://photos1.meetupstatic.com/photos/event/1/6/4/b/global_3743707.jpeg
    • </photo_url>
    • <updated>Mon Jul 21 20:35:17 EDT 2008</updated>
    • <feedesc/>
    • <questions/>
    • <name>Better Laugh Laughter Yoga Meetup</name>
    • </item>
    [email_address]
  • 13. 2) Make HTTP Request
    • Encode parameters URL or body
    • Specify method
    • Manipulate headers
    • Example: Simple GET in your browser or use curl
      • curl &quot;http://api.meetup.com/groups/?zip=10003&key=123”
    [email_address]
  • 14. Simplest way in Objective-C
    • NSString *urlString =
    • @&quot;http://api.meetup.com/…”;
    • NSURL *url = [NSURL URLWithString:urlString];
    • NSStringEncoding encoding;
    • NSError *error;
    • NSString *doc = [NSString stringWithContentsOfURL:url usedEncoding:&encoding error:&error];
    [email_address]
  • 15. More control
    • NSURLResponse *response;
    • NSError *error;
    • NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
    • // Manipulate the request
    • NSData *urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
    [email_address]
  • 16. Asynchronous way
    • NSURLConnection *connection = [NSURLConnection connectionWithRequest:urlRequest delegate:self];
    • // start ‘progress’ animation
    • -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    • [myData appendData:data];
    • }
    • - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    • // stop ‘progress’ animation and use data.
    • }
    [email_address]
  • 17. Homework
    • Extract this all out into a reusable web services client class that
      • Sets parameters and body based on HTTP method
      • Makes asynchronous calls and collects data
      • Calls back arbitrary methods on delegate
      • Load images asynchronously also
    • Hints: SEL/performSelector, also check out twitter engine
    [email_address]
  • 18. 3) Parse Results
    • NSXMLParser - SAX based parsing
    • NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
    • [parser setDelegate:self];
    • [parser parse];
    • parser: didStartElement: namespaceURI: qualifiedName: attributes:
    • parser: didEndElement: namespaceURI: qualifiedName:
    • parser: foundCharacters:
    [email_address]
  • 19. Other Options
    • Libxml2
    • http://code.google.com/p/touchcode/wiki/TouchXML
    • http://code.google.com/p/touchcode/wiki/TouchJSON
    • P Lists – NSPropertyListSerialization propertyListFromData
    [email_address]
  • 20. Things to look out for
    • Bugs in client libraries - sometimes PUT and DELETE are not well supported
    • Debugging the HTTP request response can be trying. Anyone know of a good debugging proxy?
    [email_address]
  • 21. Resources
    • programmableweb.com
    • Code besides twitter engine?
    • For REST info check out:
    [email_address]
  • 22. Questions?
    • Slides will be on http://www.E-String.com
    • Feel free to contact me:
    • Julio Barros
    • 917-445-7264
    • [email_address]
    [email_address]

×