DevNet Associate (DEVASC) v1.0Software Development and DesignMedium
A developer is designing a RESTful API for a network device management system. The API needs to allow clients to retrieve information about specific network interfaces, create new interfaces, update existing interfaces, and delete interfaces. To adhere to REST principles, which HTTP method should be used for retrieving a list of all network interfaces?
- APOST /interfaces
- BPUT /interfaces
- CDELETE /interfaces
- DGET /interfaces
Show answer & explanationAnswer & explanation
Correct answer: D. GET /interfaces
According to RESTful API design principles, the GET HTTP method is used to retrieve resources. A request to `/interfaces` with a GET method should return a list of all network interfaces without modifying the server state.
Why the other options are wrong
- A. POST is typically used to create new resources.
- B. PUT is typically used to update an existing resource or create a resource if it does not exist.
- C. DELETE is used to remove a resource.
RESTful API HTTP Methods
RESTful APIs use standard HTTP methods (verbs) to perform operations on resources. Each method has a specific semantic meaning that aligns with CRUD (Create, Read, Update, Delete) operations.
- GET: Retrieves representations of a resource (Read).
- POST: Submits data to a specified resource, often causing a change in state or creation of a resource (Create).
- PUT: Updates an existing resource or creates a new one if it doesn't exist (Update/Create).
- DELETE: Removes a specified resource (Delete).
Memory trick: GET, POST, PUT, DELETE: The CRUD of the web.