JSON & the Web

How do our applications retrieve data?

  • Web scrapers
  • Web services
  • Internal Data

REST APIs

  • Architecture used for web services that transfer data
  • Examples
    • https://developer.github.com/v3/
    • https://dev.twitter.com/rest/public

JSON

JavaScript Object Notation

{
    "students": [
        {
            "name": "Daniel Hsing",
            "age": 16, // :^)
            "school": {
                "id": 1,
                "name": "Chinese International School",
                "country": "Hong Kong"
            }
        }
    ]
}
var students = [
    {
        name: "Daniel Hsing",
        age: 16, 
        school: {
            id: 1,
            name: "Chinese International School",
            country: "Hong Kong"
        }
    }
]

JavaScript vs JSON

Transport Layer Protocol:

HTTP(S)

  • TCP Port 80 for HTTP
  • TCP Port 443 for HTTPS

HTTP Verb

GET

POST

PUT

DELETE

Function

Retrieve a resource

Create a resource

Update a resource

Remove a resource

URL Scheme

<protocol>://<host>/<path>

Resources are denoted by different paths

Browser Example

Navigate to this url:

https://www.reddit.com/r/.json

User Registration Example

HTTP Client: Postman

Endpoints

  • /api/users
    • GET
    • POST
  • /login
    • POST

Working with public web APIs

  • Registering an API key

  • Rate Limiting

Google Maps Web API

register a key at the Google API Console

Resources

JSON & the Web

By Daniel Hsing

JSON & the Web

  • 405