Server-Side Scripting/REST API

This lesson introduces REST API concepts and testing REST APIs using cURL.

Objectives and Skills

edit

Objectives and skills for this lesson include:

  • Understand REST API concepts
  • Create a REST API using server-side scripts
  • Test a REST API using cURL

Readings

edit
  1. Wikipedia: REST API
  2. Wikipedia: cURL

Multimedia

edit
  1. YouTube: REST API concepts and examples
  2. YouTube: Basic cURL Tutorial
  3. YouTube: How to build a REST API with Node js & Express

Examples

edit

Activities

edit

Complete the following activities using HTML, CSS, and a server-side scripting language. Apply best practices for user interface design and your selected scripting language, including modules, comments, indentations, naming conventions, and constants. Use HTML forms and input elements for input, server-side scripts for processing, and HTML elements for output. Use separate functions for each type of processing. Avoid global variables by passing parameters and returning results. Add comments at the top of the code modules and include references to any resources used. Add the completed code to your website as /lesson13.

  1. Create an application that allows the user to insert, update, and delete records using a REST API. After each action, display the current records. Use any key-value database or data structure you like. Be sure to include date, text, and number field types in the data structure. If in doubt, any of the previous cyclone, earthquake, or wildfire activities may be used as data examples.

Lesson Summary

edit
  • A REST API (also known as RESTful API) is an application programming interface (API or web API) that conforms to the constraints of REST architectural style and allows for interaction with RESTful web services. REST stands for representational state transfer and was created by computer scientist Roy Fielding.[1]
  • In a Representation State Transfer API, the service is not constantly connected to the other web service. The connection occurs only a the time the resource is needed, so there is not a shared state between web services.[2]
  • The goal of REST is to increase performance, scalability, simplicity, modifiability, visibility, portability, and reliability. This is achieved through following REST principles such as a client-server architecture, statelessness, cacheability, use of a layered system, support for code on demand, and using a uniform interface. These principles must be followed for the system to be classified as REST.[3]
  • In a REST API, state is transferred between the web services via requests. State is the values of the web service’s application.[4]
  • REST is stateless. The client request should contain all the information necessary to respond to a request. In other words, it should be possible to make two or more HTTP requests in any order and the same responses will be received.[5]

Key Terms

edit
Application Programming Interface (API)
Provides interactions between one software and another, but not users.[6]
endpoint
The url you request for. It follows this structure: root-endpoint/?[7]
JavaScript Object Notation (JSON)
A lightweight data-interchange format.[8]

See Also

edit

References

edit