HTTP Methods
Complete guide about HTTP methods (GET, POST, PUT, DELETE, etc.) in moclojer. Learn when to use each method and how to implement correct RESTful APIs.
Supported Methods
Method
Purpose
IdempotentΒΉ
SafeΒ²
Syntax in Moclojer
- endpoint:
method: GET # Specifies the HTTP method
path: /users
response:
status: 200
body: "..."GET - Read Data
Example: List Resources
Example: Get Specific Resource
GET with Query Parameters
When to Use GET
POST - Create Data
Example: Create Resource
POST for Custom Actions
When to Use POST
PUT - Update/Replace
Example: Update Complete Resource
PUT vs POST
When to Use PUT
PATCH - Update Partially
Example: Partial Update
PATCH vs PUT
Aspect
PUT
PATCH
When to Use PATCH
DELETE - Remove Data
Example: Delete Resource
DELETE with Confirmation
DELETE for Resource Not Found
When to Use DELETE
HEAD - Get Metadata
Example
When to Use HEAD
OPTIONS - Discover Allowed Methods
Example
CORS Preflight
Multiple Methods, Same Path
Complete RESTful API
Status Codes by Method
Method
Success
Common Error
Best Practices
β
Do
β Avoid
Next Steps
See Also
Last updated
Was this helpful?