Understanding API Styles: REST vs. RPC, Synchronous vs. Asynchronous (2.8)

Jimin
2 min readNov 20, 2023

--

Introduction

Grasping different API styles and their communication methods is crucial for network automation professionals. This post will demystify REST and RPC API styles, along with synchronous and asynchronous communications, complete with real-world examples.

REST (Representational State Transfer)

  • Overview: Uses HTTP methods, focusing on stateless operations and resource manipulation.
  • Use Case: Ideal for public-facing web services like social media APIs, where scalability and flexibility are key.
  • Example: A RESTful service for a blog where GET /posts retrieves blog posts and POST /posts creates a new post.
import requests
response = requests.get('https://api.weather.com/v1/forecast')
forecast = response.json()

RPC (Remote Procedure Call)

  • Overview: Executes predefined procedures on the server, often using XML-RPC or JSON-RPC.
  • Use Case: Best for internal or tightly coupled systems where performance and direct actions are important.
  • Example: An internal system where a client calls updateInventory(itemID, quantity) on a server to update inventory data.
import xmlrpc.client
s = xmlrpc.client.ServerProxy('http://internal.example.com/rpc')
result = s.updateInventory('12345', 100)

Synchronous Communication

  • Overview: The client waits for the server response before continuing.
  • Use Case: Necessary for operations where immediate feedback is essential, like form submissions on websites.
  • Example: A user login process where the client waits for verification before loading the user profile.
response = requests.post('https://api.payment.com/process', data=paymentData)
if response.status_code == 200:
print("Payment processed")
else:
print("Payment failed")

Asynchronous Communication

  • Overview: The client doesn’t wait for a response; it’s handled separately, allowing the client to perform other tasks.
  • Use Case: Useful for background tasks or operations requiring heavy processing.
  • Example: Sending an email through an API where the client triggers the send action but doesn’t wait for the delivery confirmation.
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
console.log('Request made, waiting for response...');

Comparing the Styles

  • REST vs. RPC: REST is resource-centric and internet-friendly, suited for public APIs and scalable applications. RPC is action-centric, efficient for smaller, tightly coupled systems.
  • Synchronous vs. Asynchronous: Synchronous is straightforward but can block processes. Asynchronous offers better performance for tasks that don’t need immediate completion.

Conclusion

Choosing the right API style and communication method is critical for effective network application development. These concepts, covered in the Cisco DevNet Associate Exam, are not just academic; they have practical implications in your everyday work. Understanding their applications, strengths, and limitations prepares you for both the exam and professional challenges.

Next in the Series: Our next post will dive into constructing a Python script to call a REST API and execute RPC commands using the requests library, a practical and essential skill for network automation. For more topics and a comprehensive guide, revisit our Navigating the DevNet Associate Exam (200–901): A Study Series overview page.

--

--

Jimin
Jimin

Written by Jimin

DevOps engineer and tech enthusiast. Sharing tech insights to simplify the complex. Let's connect on LinkedIn! https://www.linkedin.com/in/byun-jimin/

No responses yet