| Start |
|---|
| Hello world application Configuration First, create a file called Package.swift. This is the file that tells swift compiler where the libraries are located. In this hello world example, we are using GitHub repos. We need Next, create a folder called Sources. Inside, create a file called main.swift. This is the file that we implement all the logic for this application. Enter the following code into this main file. Import libraries and enable logging Adding a router. Router specifies a path, type, etc of the HTTP request. Here we are adding a GET request handler which prints Hello world, and then a post request that reads plain text from the request and then send it back. Specify a port to run the service Bind the router and port together and add them as HTTP service Execute Navigate to the root folder with Package.swift file and Resources folder. Run the following command. Swift compiler will automatically download the mentioned resources in Package.swift into Packages folder, and then compile these resources with main.swift When the build is finished, executable will be placed at this location. Double click this executable to start the server. Validate Open a browser, type in Open a HTTP request app, post plain text to |
Read Article
https://develop.horje.com/learn/1434/reference