first post!
I'm a student learning swift and I'm on a rather big crash course. My professor started teaching us how to do simple get and post requests last time, but I'm still catching up and very clearly haven't grasped some of the basics.
This is my first time working with Kitura and only the second time coding in Swift. For some reason when I use swift run
, I get my print and a sudden "Program ended with exit code : 0" rather than having a localhost running on my 8080 port to verify my get response on localhost:8080/
.
Could someone help me figure out what I'm not seeing? Or haven't understood about server-side swift and command lines?
print("Hello, world from Swift Main!")
import Kitura
//constant router
let router = Router()
//When the router gets a request (contains everything needed to interpret the request), the server will respond with (Hello World or whatever data)
router.get("/") { request, response, next in
response.send("Hello world from router.get") //response
next() //either end the route or go on to the next one
}
//What port for the server to run on
Kitura.addHTTPServer(onPort: 8080, with: router)
//Need to add routes before run(), either in different file or on main
Kitura.run()
Thanks!