Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cosc 5/4730 REST services.

Similar presentations


Presentation on theme: "Cosc 5/4730 REST services."— Presentation transcript:

1 Cosc 5/4730 REST services

2 What is REST? REST stands for Representational State Transfer.
It is sometimes spelled "ReST". It relies on a stateless, client-server, cacheable communications protocol -- and in virtually all cases, the HTTP protocol is used. The idea is that, rather than using complex mechanisms such as CORBA, RPC or SOAP to connect between machines, simple HTTP is used to make calls between machines.

3 What is REST? (2) RESTful applications use HTTP requests to post data (create and/or update), read data (e.g., make queries), and delete data. Thus, REST uses HTTP(s) for all four CRUD (Create/Read/Update/Delete) operations. Sound familiar? Think ContentProvider! The returned data maybe some combination of HTML, XML, JSON, etc. Up to the API There really is no standard.

4 What is REST? (2) The web services may or may not require authentication. For security, username/password tokens are often used. For encryption, REST can be used on top of HTTPS (secure sockets). Again, depends on the app.

5 Real world examples Google’s Mirror API is a REST API
Twitter has a REST API This was their original API and, so far as I can tell, it's still the main API used by Twitter application developers), Flickr Amazon.com offer several REST services, e.g., for their S3 storage solution Atom is a RESTful alternative to RSS,

6 Standards (not really)
There is only really one standard. It uses a webserver The request may look like this for all the posts for the first post. for all posts for the first post The data is returned as csv file, json, xml, or other format.

7 JSON and android Android has built in methods for JSON Import org.json
Data is started in a Key value format in a JSONObject JSONObject which can be a mix of JSONObjects and JSONArrays JSONArray which is an array of JSONobjects A good simple tutorial is here:

8 REST and JSON demo RestDemo1 It shows basics of JSON
Uses a REST service designed for testing purposes It loads the data via a HttpURLconnection (and AsyncTask) Display the data in recyclerview with a refreshlayout.

9 Creating your own. Can be a simple or complex as you need
Maybe combined with AJAX (via java script) calls as well Think Google’s search that updates as you type. The backend language is your choosing, but normally a script running via the webserver It then access to a backend storage (ie file, database, etc) At min it should have some way to query for information Updating, deleting, and inserting data are based on need.

10 ReST Demo 2 Uses php and database on a webserver.
The query data is returned in a csv format. Delete and update require an the use of the id value. Insert just requires the other values. Authentication is required basic authentication via the web server

11 authenticator Uses the java.net.Authenticator and java.net.PasswordAuthentication packages. In it’s simple form, you need to set the username and password for the authenticator Authenticator.setDefault(new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password.toCharArray()); }); Where both username and password are Strings.

12 Post and parameters. A get access looks like this:
Where there are two parameters param1=value Param2=anothervalue In a post method, it is in the request It can be very complex for file uploads, but parameters can be done simply. “param1=value&parm2=anothervalue” written out URL encoded UTF-8 format. Then use the outputStream to write to the web server. See the getPostDataString method is RestDemo2.

13 ReST Demo 3 It’s an attempt a system that displays pictures similar in concept to facebook, tumbler, and instragram. It uses a asyncTask to get the data for the recyclerview And a second task to load the images as the cardview for it becomes visible.

14 References http://rest.elkstein.org/2008/02/what-is-rest.html
For post parameters method.

15 Q A &


Download ppt "Cosc 5/4730 REST services."

Similar presentations


Ads by Google