Quiz

  1. I think I'm having a hard time understanding how the different concepts introduced in the reading (APIs, JSON, REST, Ajax, Flask, and Python) are connected to each other and work together.

    Who could blame you? I'll try to draw some pictures.

  2. Does Ajax have its own API? How does Ajax relate to REST API?

    They're different ideas, though related.

    • Ajax is the JS, running the browser, sending a web request and handling the response, asynchronously with user interaction with the page.
    • Most of the time, Ajax uses the HTTP protocol (though it can use others, like web sockets).
    • A back-end service can provide data using a REST API.
    • A browser might use Ajax to interact with a REST API.
  3. How is jsonify() different from json.dumps()?

    Very similar. Jsonify also wraps up the result in a proper response object.

  4. Is it necessary for the developer to specify all status codes or can the browser recognize them itself?

    The front-end developer? The browser already knows all the codes, but it doesn't necessarily handle them in a nice, graceful way.

    And, of course, your JS code is on its own. So, your Ajax code may need to detect error status code and handle them appropriately (retry, notify the user, etc)

  5. Can you go over more about the difference between post and put? Is post used for an initial creation? And put can be used over and over again?

    Yes, that's right. We can use POST is all kinds of ways, but in a REST API, it should be used for creating an entity, while PUT is used for updating an enemy.

    But these are more guidelines than actual rules, per se.