DevNet Associate (DEVASC) v1.0Software Development and DesignMedium

A developer is designing an API for a network monitoring application. The API needs to allow clients to retrieve a list of all active network devices. For each device, the API should return its unique identifier, hostname, and status. Which HTTP method and URL path structure are most appropriate for this endpoint, following RESTful principles?

  1. APOST /devices/active
  2. BGET /get_active_devices
  3. CPUT /devices/active
  4. DGET /devices?status=active
Show answer & explanation

Correct answer: D. GET /devices?status=active

According to RESTful principles, `GET` is used to retrieve resources. Filtering a collection (like devices by status) is typically done using query parameters. Thus, `GET /devices?status=active` is the most appropriate and idiomatic RESTful approach.

Why the other options are wrong

  • A. `POST` is used to create new resources, not retrieve existing ones with filters.
  • B. While functionally a `GET` request, `/get_active_devices` is not RESTful. REST emphasizes resource-based URLs (nouns like `/devices`) and uses HTTP methods (verbs) to indicate the action on those resources, avoiding verbs in the URL path itself.
  • C. `PUT` is used to update or replace an existing resource, not to retrieve a list of resources.

RESTful API Design

REST (Representational State Transfer) is an architectural style for designing networked applications. RESTful APIs use standard HTTP methods and resource-based URLs to enable stateless communication between client and server.

  • Uses standard HTTP methods (GET, POST, PUT, DELETE)
  • Resource-based URLs (nouns, not verbs)
  • Stateless communication
  • Client-server architecture
  • Uniform interface

Memory trick: REST uses HTTP verbs on resource nouns, keeping communication clean.

More Software Development and Design questions