https://github.com/coldgrub1384/swiftyweb
Swift CGI helper
https://github.com/coldgrub1384/swiftyweb
cgi cgi-script linux macos swift swift3 swiftlibrary webserver
Last synced: 5 months ago
JSON representation
Swift CGI helper
- Host: GitHub
- URL: https://github.com/coldgrub1384/swiftyweb
- Owner: ColdGrub1384
- License: mit
- Created: 2017-12-18T20:03:06.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-08T22:09:27.000Z (over 7 years ago)
- Last Synced: 2025-03-13T12:28:52.403Z (11 months ago)
- Topics: cgi, cgi-script, linux, macos, swift, swift3, swiftlibrary, webserver
- Language: Swift
- Homepage: https://coldgrub1384.github.io/SwiftyWeb
- Size: 337 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftyWeb


## Swift library for CGI
- [x] Global variables and functions
- [x] No need to recompile for each edit (but supported)
- [x] Automatic library integration, no Package Manager
- [x] Show compiler errors in browser
- [ ] MySQL
SwiftyWeb includes a Swift helper for CGI.
You can use it like this:
```swift
// GET
"h1".htm() {
print("GET Parameters")
}
"ul".htm() {
for (key, value) in GET {
"li".htm() {
print(key+":"+value)
}
}
}
// POST
"h1".htm() {
print("POST Parameters")
}
"ul".htm() {
for (key, value) in POST {
"li".htm() {
print(key+":"+value)
}
}
}
```
# Usage
Init a project, install via the package manager, compile and move?
NO.
With SwiftyWeb, you can simply write your code and open the browser.
## Linux and Mac
Install typing this in a shell:
curl https://raw.githubusercontent.com/ColdGrub1384/SwiftyWeb/master/install 2>/dev/null | sudo bash
Or, inside this repo, run:
./install nodownload
### Slow method
Now, you can write Swift CGIs putting this in the top or your file:
#!/usr/bin/swiftw
// Your code here
(Don't forget to chmod +x your file)
You can also include other files:
#!/usr/bin/swiftw AnotherFile.swift
// Your code here
### Fast method
Loading CGIs with '#!/usr/bin/swiftw' is very slow, you can compile files manually typing:
swiftw -o PATH_TO_NEW_EXECUTABLE FILES TO COMPILE
A file will be created and you can put it in your CGI's folder.
## Mac
In Mac, you can also build the framework opening `SwiftyWeb.xcodeproj` and include framework in your command line project. Don't forget to print `"Content-Type: text/html\nContent:\n"`!
# Documentation
If you want to contribute to the documentation, don't edit the `docs` directory, but just [document the code](http://nshipster.com/swift-documentation/), the page will be generated by me with [Jazzy](https://github.com/realm/jazzy), or if you want, generate it yourself.
## Generate documentation
- Install Jazzy:
`[sudo] gem install jazzy`
- And run the [`build-documentation.sh`](https://github.com/ColdGrub1384/SwiftyWeb/blob/master/build-documentation.sh) script inside this repo.
- Increment `version` field in [`docs/docsets/Pisth.xml`](https://github.com/ColdGrub1384/SwiftyWeb/blob/master/docs/docsets/SwiftyWeb.xml).
# Example
My web page is coded with SwiftyWeb: [colg.ddns.net](https://github.com/ColdGrub1384/coldg.ddns.net)