Web APIs

  • Interface to Web Application
  • Access & Modify Server Resources
  • Defines Endpoints, Parameters, Responses
  • Built on HTTP

Example - Twilio

EXCLAMATION_MARK='!'
curl -X POST https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json \
--data-urlencode "Body=Hi there$EXCLAMATION_MARK" \
--data-urlencode "From=+15017122661" \
--data-urlencode "To=+15558675310" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN

Response

{
    "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "api_version": "2010-04-01",
    "body": "Hi there!",
    "date_created": "Thu, 30 Jul 2015 20:12:31 +0000",
    "date_sent": "Thu, 30 Jul 2015 20:12:33 +0000",
    "date_updated": "Thu, 30 Jul 2015 20:12:33 +0000",
    "direction": "outbound-api",
    "error_code": null,
    "error_message": null,
    "from": "+14155552345",
    "messaging_service_sid": null,
    "num_media": "0",
    "num_segments": "1",
    "price": null,
    "price_unit": null,
    "sid": "SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    "status": "sent",
    "subresource_uris": {
        "media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Media.json"
    },
    "to": "+14155552345",
    "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/SMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.json"
}

REST

  • Arch. Style
  • JSON, HTML, etc.
  • HTTP
  • Suggested Interaction Model

SOAP

  • Web Standard
  • XML
  • Structured
  • No Interaction Model

Documentation

  • RESTful API DLs
  • Endpoints
  • Parameters
  • Responses

OpenAPI Example


paths:
    # Whole board operations
    /board:
        get:
            summary: Get the whole board
            description: Retrieves the current state of the board and the winner.
            responses:
                "200":
                    description: "OK"
                    content:
                        $ref: "#/components/schemas/status"
schemas:
    status:
        type: object
        properties:
        winner:
            $ref: "#/components/schemas/winner"
        board:
            $ref: "#/components/schemas/board"
    board:
        type: array
        maxItems: 3
        minItems: 3
        items:
            type: array
            maxItems: 3
            minItems: 3
            items:
            $ref: "#/components/schemas/mark"
    winner:
        type: string
        enum: [".", "X", "O"]
        description: Winner of the game. `.` means nobody has won yet.
        example: "."
    

Authentication

  • HTTP Authentication
  • API Keys
  • OAuth