-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME
More file actions
77 lines (55 loc) · 1.94 KB
/
Copy pathREADME
File metadata and controls
77 lines (55 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 📌 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!** 😃🔥