Chapter 4 Flashcards
____ help to:
avoid a server overload from too many requests at once
provide better service and response time to all users
protect against a denial-of-service (DoS) attack
Rate Limits
Rate limits commom algorithms:
Leaky bucket
Token bucket Fixed window counter Sliding window counter
Puts all incoming requests into a request queue in the order in which they were received.
Leaky bucket (Rate limit)
Gives each user a defined number of tokens they can use within a certain increment of time, and those tokens accumulate until they’re used.
Token Bucket
-It uses a counter rather than a collection of tokens.
-The counter cannot be accumulated.
-Fixed Window
Allows a fixed number of requests to be made in a set duration of time. This duration of time is not a fixed window and the counter is not replenished when the window begins again.
The sliding window (Rate limit)
HTTP 429
Too many requests
Is an HTTP callback, or an HTTP POST, to a specified URL that notifies your application when a particular activity or “event” has occurred in one of your resources on the platform.
Webhook
Webhooks are also known as…..
reverse APIs
-The application must be running at all times to receive HTTP POST requests.
-The application must register a URI on the webhook provider so that the provider knows where to send a notification when target events occur.
requirements for receiving a notification from a webhook provide.
import requests
uri = “sandboxdnac.cisco.com/dna/intent/api/v1/network-device”
resp = requests.get(uri, verify = False)
Invalid URI example
R/ Perhaps you meant http://sandboxdnac.cisco.com/dna/intent/api/v1/network-device?….
import requests
url = “https://sandboxdnac123.cisco.com/dna/intent/api/v1/network-device”
resp = requests.get(url, verify = False)
….requests.exceptions.ConnectionError: HTTPSConnectionPool(host=’sandboxdnac123.cisco.com’, port=443): Max retries exceeded with url: /dna/intent/api/v1/network-device (Caused by NewConnectionError(‘<urllib3.connection.VerifiedHTTPSConnection object at 0x109541080>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known’))….
Wrong domain name
Status code categories:
-1xx: Informational: Request received, continuing to process.-
-2xx: Success: The action was successfully received, understood, and accepted.- -3xx: Redirection: Further action must be taken in order to complete the request.- -4xx: Client Error: The request contains bad syntax or cannot be fulfilled.- -5xx: Server Error: The server failed to fulfill an apparently valid request.-
Use cases for APIs….
Automation tasks
-Build a script tat performs your manual tasks automatically and programmatically.- (administration software)
Data integration-
-An application can consume or react to data provided by another application. (e-comerce website)-
Functionality
-An application can integrate another application’s functionality into it;s product. (Uber + Google maps)-
It is an architecture style for designing web service applications.
REST