Usint Charles Proxy to understand REST

28
Using Charles Proxy to understand REST (c) [email protected]

Transcript of Usint Charles Proxy to understand REST

Page 1: Usint Charles Proxy to understand REST

Using Charles Proxyto understand REST

(c) [email protected]

Page 2: Usint Charles Proxy to understand REST

The Fundamentals

Web debugging proxy

REST

JSON

Page 3: Usint Charles Proxy to understand REST

What is Charles Proxy ???

Page 4: Usint Charles Proxy to understand REST

It is Web Debugging Proxy

Helps analyse trafic

Captures HTTP and HTTPS traffic

Implements man-in-the-middle HTTPS interception using self-signed certificates

Useful features for bandwidth throttling, mapping local or remote url

Works on MacOS, Linux and Windows

Free version allow 30 minutes sessions

Page 5: Usint Charles Proxy to understand REST

–REpresentational State Transfer

“REST”

Page 6: Usint Charles Proxy to understand REST

REST

It is not specification

It is ARCHITECTURE STYLE that:

client-server

statelessness

Page 7: Usint Charles Proxy to understand REST

HTTP Verbs

POST

GET

PUT

DELETE

PATCH

Page 8: Usint Charles Proxy to understand REST

C.R.U.D. Operations

Create -> POST

Read -> GET

Update -> PUT*

Delete -> DELETE

* PUT is also used for creating

Page 9: Usint Charles Proxy to understand REST

HTTP Codes

1xx Informational

2xx Success

3xx Redirection

4xx Client Error

5xx Server Error

Page 10: Usint Charles Proxy to understand REST

API Design: BAD

/getUser

/getAllUsers

/findUser

/findUserAccounts

/deleteUser

/changeUserPassword

Resources are Plural Nouns. Do not use Verbs!

Page 11: Usint Charles Proxy to understand REST

API Design

Collection

/users

Entities

/users/adam

/users/13246

Page 12: Usint Charles Proxy to understand REST

API Design

verb\ resource POST GET PUT DELETE

/users New User List Users ? delete everybody

/users/adam ? show Adam update/create Adam Delete Adam

Page 13: Usint Charles Proxy to understand REST

API Design: resources chain

/users/adam/accounts

Page 14: Usint Charles Proxy to understand REST

API Versioning

Just integer /v1/users/…

Decimal point /v1.0/users/…

Date /2015-11-11/…

In query string …?v=1

In http header

Page 15: Usint Charles Proxy to understand REST

–JavaScript Object Notation

“JSON”

Page 16: Usint Charles Proxy to understand REST

Object

Value

Array

Number

Syntax diagrams (or railroad diagrams) are a way to represent a context-free grammar.

Page 17: Usint Charles Proxy to understand REST

{ "city":{"id":1851632,"name":"Shuzenji", "coord":{"lon":138.933334,"lat":34.966671}, "country":"JP", "cod":"200", "message":0.0045, "cnt":38, "list":[{ "dt":1406106000, "main":{ "temp":298.77, "temp_min":298.77, "temp_max":298.774, "pressure":1005.93, "sea_level":1018.18, "grnd_level":1005.93, "humidity":87 "temp_kf":0.26}, "weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}], "clouds":{"all":88}, "wind":{"speed":5.71,"deg":229.501}, "sys":{"pod":"d"}, "dt_txt":"2014-07-23 09:00:00” }] }

json sample from openweathermap.org

Page 18: Usint Charles Proxy to understand REST

Header

Content-Type: application/json

Page 19: Usint Charles Proxy to understand REST

Charles Proxy–Install and Configure

Page 20: Usint Charles Proxy to understand REST

Install

download from official site http://www.charlesproxy.com/

http://www.charlesproxy.com/download/

For Linux use APT or tar.gz from download page

follow the instructions from site http://www.charlesproxy.com/documentation/installation/

latest MacOs version use embedded JRE

Page 21: Usint Charles Proxy to understand REST

Run and check Settings at Proxy->Proxy Settings…

Page 22: Usint Charles Proxy to understand REST

Configure SSL Proxy

For versions below 3.10 follow instructions from Legacy SSL page on official site http://www.charlesproxy.com/documentation/additional/legacy-ssl-proxying

New versions do not use common certificate

Just go to Help->SSL Proxying and select corresponding option

for iOS/Android it is “Install Charles Root Certificate on Mobile Device or Remote Browser”. And follow instructions

Page 23: Usint Charles Proxy to understand REST

Configure SSL Proxy

Page 24: Usint Charles Proxy to understand REST

Configure Android phone to use proxy

Open Settings->WiFi

Long press on target access point

Select Modify Network

In Access Point settings check Advanced Options

Enter IP address and port (8888 by default)

Page 25: Usint Charles Proxy to understand REST

On your laptop allow connection from remote device

Page 26: Usint Charles Proxy to understand REST

Configure Android phone to use proxy

Open in mobile browser link http://charlesproxy.com/getssl

Enter name and tap OK button

It is all you have to do on Android side

Page 27: Usint Charles Proxy to understand REST

Enable and configure target: Menu Proxy->SSL Proxying Settings

Page 28: Usint Charles Proxy to understand REST

–show must go on

Real world demo