Skip to content

Files

Latest commit

 

History

History

quick.delete

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
# πŸ“Œ DELETE - Quick Framework ![Quick Logo](/quick.png)

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!** πŸ˜ƒπŸ”₯