REST API and JSON (WE/NIS)

What is a REST API?

A REST API, or RESTful API, is a type of application programming interface (API) that follows the principles of Representational State Transfer (REST) architectural style. It allows communication between different applications or systems over the internet, typically using HTTP requests and responses. Think of it as a set of instructions for how to interact with a specific piece of software or service.

What are the benefits of using APIs?

  • Increased Efficiency: APIs automate tasks, saving developers time and resources.
  • Improved Functionality: APIs provide access to specialized data and functionality, enhancing applications.
  • Easier Integration: APIs simplify communication between different systems, regardless of their programming language.
  • Scalability: APIs enable applications to handle increased traffic and data volumes.
  • Flexibility: APIs offer flexibility for developers to build custom applications and integrations.

 

What is a URI?

A URI (Uniform Resource Identifier) is a unique identifier for a resource on the internet, like a web page, image, or API endpoint. It tells the system where to find the specific resource you’re requesting. In REST APIs, URIs often include the resource type and specific identifier (e.g., /users/123).

What are API methods?

API methods are specific actions you can perform on a resource using the API. Common methods include GET (retrieve data), POST (create data), PUT (update data), and DELETE (remove data). These methods are typically mapped to HTTP verbs for clear communication.

What are the key design principles of APIs?

Resource-based: Treat data and functionality as resources with unique identifiers.

Stateless: Each request-response interaction is independent, and the server doesn’t store state information.

Cachable: Responses can be cached for improved performance.

Uniform interface: Use consistent naming conventions and methods across the API.

Documenting: Provide clear documentation for developers to understand how to use the API effectively.

What is JSON?

JSON (JavaScript Object Notation) is a popular data format for exchanging information between applications. It uses a human-readable format with key-value pairs, making it lightweight and easy to parse. APIs often use JSON to send and receive data, making it a crucial element in API communication.

Example JSON File:

{

  “name”: “John Doe”,

  “age”: 30,

  “occupation”: “Software Engineer”,

  “interests”: [“coding”, “travel”, “music”],

  “address”: {

    “street”: “123 Main Street”,

    “city”: “Anytown”,

    “state”: “CA”,

    “zipcode”: “12345”

  }

}

This example represents information about a person in JSON format. It uses key-value pairs to store data like name, age, occupation, interests, and address. The address itself is another object nested within the main object.

Key Benefits of JSON:

  • JSON uses a simple and clear format with key-value pairs, making it easy for humans to understand and edit.
  • JSON files are compact and require minimal data overhead, making them ideal for network transmission and storage.
  • JSON is not tied to any specific programming language, making it easily usable in various development environments.
  • JSON allows for nested objects and arrays, providing flexibility in representing complex data structures.
  • The structure and data types are readily apparent within the JSON file, eliminating the need for separate schema definitions.
  • JSON is a de facto standard for data exchange, supported by most programming languages, web frameworks, and databases.

 

See a video below on APIs

 

 

Published by Active Learning, Dec 2023