Skip to content

CoAP DELETE Request Returns 4.05 Method Not Allowed

DodaTech Updated 2026-06-26 1 min read

In this tutorial, you'll learn about CoAP DELETE Request Returns 4.05 Method Not Allowed. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

CoAP DELETE request fails with 4.05 (Method Not Allowed) response.

Quick Fix

Wrong

// No handler registered for DELETE method```

Client receives 4.05 Method Not Allowed.


### Right

```cpp
#include <coap.h>

static coap_resource_t *temp_resource = NULL;

void delete_handler(coap_context_t *ctx, coap_resource_t *res,
                    coap_session_t *session, coap_pdu_t *request,
                    coap_binary_t *token, coap_string_t *query,
                    coap_pdu_t *response) {
  // Remove resource from the server
  coap_delete_resource(ctx, res);
  coap_pdu_set_code(response, COAP_RESPONSE_CODE_DELETED);

  // Notify observers if using Observe
  coap_resource_notify_observers(res, NULL);
}

int main() {
  coap_context_t *ctx = coap_new_context(NULL);
  temp_resource = coap_resource_init((const uint8_t*)"temperature", 11, 0);
  coap_register_handler(temp_resource, COAP_REQUEST_DELETE, delete_handler);
  coap_add_resource(ctx, temp_resource);
  coap_start(ctx);
}```

Client receives 2.02 Deleted. /temperature resource is removed.


## Prevention

CoAP DELETE removes a resource. Return 2.02 (Deleted) on success. You must register a handler for DELETE method. If no handler is registered, the server responds with 4.05 (Method Not Allowed). After deletion, GET returns 4.04 (Not Found). Notify observers if Observe was active on the resource.

DodaTech engineers apply these same patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro for production IoT reliability.

## FAQ

<details style="margin-bottom:12px;border:1px solid #e2e8f0;border-radius:10px;overflow:hidden"><summary style="cursor:pointer;padding:14px 18px;font-weight:600;font-size:1.05rem;background:#f8fafc;border-bottom:1px solid #e2e8f0;color:#1e293b">### What response code for delete?</summary><div style="padding:14px 18px;color:#475569;line-height:1.7;background:#fff"><p>2.02 (Deleted) on success. 4.04 (Not Found) if the resource doesn't exist. 4.05 (Method Not Allowed) if no DELETE handler.</p>
<h3 id="can-i-delete-non-existing-resource">Can I delete non-existing resource?</h3><p>Return 4.04 Not Found. The resource may have already been deleted or never existed.</p>
<h3 id="what-about-observe-observers">What about Observe observers?</h3><p>Notify observers before deletion. After deletion, they receive 4.04 on next notification or timeout.</p>
</div></details>

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro