Introduction to REST APIs

A Self-Guided Tutorial

  • Use the arrow keys (← ↑ ↓ →) to navigate through the slides.
  • If viewing on a mobile/touch device, you may swipe to change slides.
  • Welcome!

    This tutorial will guide you step-by-step through understanding REST APIs and how to use tools like Postman, Curl, and Insomnia.

    • Take your time to practice the examples and follow the instructions.
    • Links to helpful resources are included for deeper learning.
    • If you get stuck, revisit earlier slides or check the helpful links.

    What is an API?

    • API = Application Programming Interface
    • Enables software systems to talk to each other
    • Like a waiter taking your order and bringing your food
    • Provides a way to request and exchange data

    Helpful Material:
    What is an API? | MuleSoft (video)
    APIs for Beginners

    What is REST?

    • REST = Representational State Transfer
    • A style for designing network communications
    • Uses standard web protocols (HTTP)
    • Works with resources (data objects) via URLs

    Helpful Material:
    REST API concepts explained
    RESTful web services explained with examples

    Why REST APIs Matter

    • Common way for apps to communicate
    • Powers many websites and mobile apps
    • Easy to use with tools like Postman, Curl
    • Helps automate and integrate workflows

    Helpful Material:
    What are APIs and why are they everywhere | Dev.to

    REST API Basics - Resources & Endpoints

    • Resource = a specific data object (user, product)
    • Endpoint = URL for accessing a resource e.g. https://api.example.com/users
    • Think of endpoints like addresses you send messages to

    HTTP Methods - What You Can Do

    • GET: Read data (e.g., get a user list)
    • POST: Create data (add a new user)
    • PUT: Update data (change user info)
    • DELETE: Remove data (delete a user)

    Helpful Material:
    HTTP methods explained

    Status Codes - What the Server Tells You

    • 200 OK: Success
    • 201 Created: Data created successfully
    • 400 Bad Request: Invalid input
    • 404 Not Found: Resource doesn’t exist
    • 500 Server Error: Problem on the server side

    Helpful Material:
    HTTP status codes explained

    How REST APIs Work

    • Client sends HTTP request to server endpoint
    • Server processes and sends back a response
    • Request includes URL, method, headers, optional body
    • Response includes status code, headers, body (usually JSON)

    Helpful Material:
    How Rest APIs work: A simple explanation | DevMagz.com

    Tools to Use REST APIs

    • Postman: Visual tool to send requests and view responses
    • Insomnia: Friendly REST API client for building, debugging, and testing APIs
    • Curl: Command-line tool to send API requests

    Helpful Material:
    Postman: Getting Started
    Using Curl
    Insomnia: Getting Started

    Hands-On Tutorial: Making GET & POST Requests

    Part 1: Using the Postman Echo API (Echo Endpoint)

    GET Request with Postman Echo

    1. Open Postman
    2. Create a new GET request to:
    https://postman-echo.com/get?sample=test
    1. Click Send
    2. Observe JSON response showing your URL, query params, headers

    POST Request with Postman Echo

    1. Create a POST request to:
    https://postman-echo.com/post
    1. Select Body tab, choose raw and JSON format
    2. Enter JSON data:
    
          {
            "message": "Hello, Postman!"
          }
          
    1. Click Send
    2. Observe response echoes your JSON payload

    Hands-On Tutorial (continued): Using JSONPlaceholder API

    GET All Posts

    1. Create a GET request for all posts:
    https://jsonplaceholder.typicode.com/posts
    1. Click Send and view JSON list of posts

    GET Single Post

    1. Create a GET request for a single post:
    https://jsonplaceholder.typicode.com/posts/1
    1. Click Send and view post details

    POST New Post

    1. Create a POST request:
    https://jsonplaceholder.typicode.com/posts
    1. In Body tab, raw JSON:
    {
      "title": "foo",
      "body": "bar",
      "userId": 1
    }
    
    1. Click Send
    2. Observe created post with an id returned

    Bonus: Curl & Windows cmd Line

    Get with Curl using Postman Echo:

    curl "https://postman-echo.com/get?sample=test"

    Post JSON with Curl:

    curl -X POST -H "Content-Type: application/json" -d "{\"message\":\"Hello, Curl!\"}" https://postman-echo.com/post
                  

    Get posts with Curl using JSONPlaceholder:

    curl "https://jsonplaceholder.typicode.com/posts"

    Post new post with Curl:

    curl -X POST -H "Content-Type: application/json" -d "{\"title\":\"foo\",\"body\":\"bar\",\"userId\":1}" https://jsonplaceholder.typicode.com/posts
                  

    Helpful Material:
    Curl official documentation

    Reading API Messages Back and Forth

    • Response typically in JSON – key/value pairs
    • Check status code first (200 = success)
    • Look at response body for data or error message
    • Troubleshoot using status codes and messages

    Helpful Material:
    JSON syntax overview
    JSON Introduction
    Common Postman Troubleshooting Scenarios | Guru99.com

    Applying REST API Knowledge

    • Explore different endpoints & methods in sample APIs
    • Practice CRUD operations using Postman or Curl
    • Consider real applications (weather, users, posts)
    • Document your findings and workflows

    Tips and Best Practices

    • Always read API documentation carefully
    • Use Postman collections to organize requests
    • Keep API keys private and secure
    • Practice regularly with public APIs
    • Use Insomnia or similar to document and review learning

    Helpful Material:
    Public APIs list | GitHub

    Summary & Next Steps

    • REST APIs let software communicate over HTTP using URLs
    • Core methods: GET, POST, PUT, DELETE
    • Tools like Postman, Insomnia and Curl simplify testing
    • Practice with Echo API and JSONPlaceholder to build confidence
    • Keep exploring, testing, and documenting!

    You’ve Reached the End!

    Congratulations on completing the REST APIs self-guided tutorial.

    Next Steps:

    • Practice regularly by exploring public REST APIs and building your own requests.
    • Use tools like Postman and Insomnia to test new APIs you discover.
    • Read API documentation carefully and apply troubleshooting tips from the tutorial.
    • Bookmark these helpful resources:
    • Share your knowledge or revisit this tutorial anytime for a refresher.

    Thank you for learning with us!