Start is a common term in web applications that refers to starting the web server and making it ready to handle HTTP requests.
In the Quick Framework, the server starts when you:
- Create an instance of Quick.
- Define your routes (GET, POST, etc.).
- Call
Listen(), specifying the port for the server.
package main
import "github.com/jeffotoni/quick"
func main() {
q := quick.New() // Initialize Quick Framework
// Define a route for "/v1/user"
q.Get("/v1/user", func(c *quick.Ctx) error {
c.Set("Content-Type", "application/json") // Set response type
return c.Status(200).SendString("Quick in action com CORS ❤️!") // Response message
})
// Start the server on port 8080
q.Listen("0.0.0.0:8080")
}$ curl --location --request GET "http://localhost:8080/v1/user" \
--header "Content-Type: application/json"You can add more routes to handle different API endpoints:
package main
import "github.com/jeffotoni/quick"
func main() {
q := quick.New() // Initializes the Quick framework
// Sets a GET route for "/v1/user"
q.Get("/v1/user", func(c *quick.Ctx) error {
c.Set("Content-Type", "application/json") // Sets the content type as JSON
return c.Status(200).SendString("Quick in action with Cors❤️!") // Returns a success message
})
// Sets a GET route for "/v2"
q.Get("/v2", func(c *quick.Ctx) error {
c.Set("Content-Type", "application/json") // Sets the content type as JSON
return c.Status(200).SendString("Is in the air!") // Returns a message indicating that the service is active
})
// Sets a GET route for "/v3"
q.Get("/v3", func(c *quick.Ctx) error {
c.Set("Content-Type", "application/json") // Sets the content type as JSON
return c.Status(200).SendString("Running!") // Returns a message confirming that the server is running
})
// Starts the server on port 8080, allowing connections from any IP
q.Listen("0.0.0.0.0.0:8080")
}
# Test endpoint v1/user
curl --location --request GET "http://localhost:8080/v1/user" \
--header "Content-Type: application/json"# Test endpoint v2
curl --location --request GET "http://localhost:8080/v2" \
--header "Content-Type: application/json"# Test endpoint v3
curl --location --request GET "http://localhost:8080/v3" \
--header "Content-Type: application/json"- ✅ Explanation of how to start a Quick server.
- ✅ Minimal example for starting a server with a simple route.
- ✅ Expanded example with multiple API routes.
- ✅ cURL commands to test different endpoints.
Now you can complete with your specific examples where I left the spaces