You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# π DELETE - Quick Framework 
This example demonstrates how to create a DELETE route in the Quick Framework to remove a user from the `/v1/user/:id` endpoint.
### π Code Implementation
```go
package main
import (
"log"
"net/http"
"github.com/jeffotoni/quick"
)
// User struct defines a user with Name and Year of birth
type User struct {
Name string `json:"name"` // User's name
Year int `json:"year"` // User's birth year
}
func main() {
q := quick.New()
// Simulating a "database" with pre-registered users
users := map[string]User{
"1": {Name: "Maria", Year: 2000}, // Fixed user with ID 1
}
// DELETE route to remove a user by ID
q.Delete("/v1/user/:id", func(c *quick.Ctx) error {
userID := c.Params["id"] // Retrieve user ID from URL parameter
// Check if the user exists in the "database"
if _, exists := users[userID]; !exists {
return c.Status(http.StatusNotFound).JSON(map[string]string{"error": "User not found"})
}
// Delete the user from the "database"
delete(users, userID)
// Return a success response
return c.Status(http.StatusOK).JSON(map[string]string{"msg": "User deleted successfully!"})
})
// Start the server on port 8080
log.Fatal(q.Listen("0.0.0.0:8080"))
}
```
#### π Testing with cURL
##### πΉDeleting an Existing User:
```bash
$ curl --location --request DELETE 'http://localhost:8080/v1/user/1'
```
#### π Now you can run the server using:
```bash
$ go run main.go
```
---
#### π What I included in this README
- β Overview of the DELETE endpoint in Quick Framework
- β Go implementation with a simulated database (map[string]User)
- β DELETE route to remove users dynamically
- β Handling of success (200 OK) and error (404 Not Found) responses
- β cURL examples for testing API behavior
Now you can **complete with your specific examples** where I left the spaces
##### π **If you need adjustments or improvements, just let me know!** ππ₯