Quick Start
Get up and running with SwiftX in under 5 minutes.
Quick Start
This guide will help you create your first SwiftX application and get it running on your local machine.
Prerequisites
- Swift 6.0+ installed on your system.
- Basic knowledge of Swift programming.
Installation
Add SwiftX as a dependency in your Package.swift file:
dependencies: [
.package(url: "https://github.com/swiftxcity/swiftx.git", from: "1.0.0")
],
targets: [
.executableTarget(
name: "MyProject",
dependencies: [
.product(name: "SwiftX", package: "swiftx")
]
)
]Your First App
Create a main.swift file in your project's Sources directory and add the following code:
import SwiftX
let app = SwiftX()
// Define a simple route
app.get("/") { req, res in
return .text("Hello, SwiftX!")
}
// Route with path parameters
app.get("/hello/:name") { req, res in
let name = req.param("name") ?? "Guest"
return .json(["message": "Welcome, \(name)!"])
}
// Start the server
app.start(port: 5100)Running the App
Run the following command in your terminal:
swift run MyProjectYour server should now be running at http://localhost:5100.
Next Steps
Explore the Routing documentation to learn more about defining routes and handling requests.
