Comments (17)
hi @jchannon
I've not seen it yet.
I've just had a quick look at it looks like a nice source of:
- templates language support
- DSL for requests handling
I will take my time on this.
best
from swifter.
I contribute to a C# framework - http://nancyfx.org which is inspired from Sinatra
Would be good to see a Swift inspired fwk too 😄
from swifter.
@jchannon wow, I really like this:
Get["/greet/{name}"] =
from swifter.
Lets do it! 😄
from swifter.
+1
from swifter.
You could do it somewhat like this:
class HttpServer {
enum Method : String {
case Get = "GET"
case Head = "HEAD"
case Post = "POST"
case Put = "PUT"
case Delete = "DELETE"
}
struct Router {
let method: Method
var handlers: [(expression: NSRegularExpression, handler: Handler)] = []
init(_ method: Method) {
self.method = method
}
subscript(path: String) -> Handler? {
get {
return nil
}
set (newValue) {
do {
let regex = try NSRegularExpression(pattern: path, options: NSRegularExpressionOptions(rawValue: 0))
if let handler = newValue {
handlers.append(expression: regex, handler: handler)
}
} catch {
}
}
}
}
var Get = Router(.Get)
var Head = Router(.Head)
var Post = Router(.Post)
var Put = Router(.Put)
var Delete = Router(.Delete)
// ...
}
var server = HttpServer()
server.Get["/login"] = { ... }
server.Post["/login"] = { ... }
from swifter.
Of course you could also do it like Nancy:
class MyServer: HttpServer {
override init() {
super.init()
Get["/login"] = { ... }
Post["/login"] = { ... }
}
}
from swifter.
Nice!!
On Thursday, 25 June 2015, Jayson Rhynas [email protected] wrote:
Of course you could also do it like Nancy:
class MyServer: HttpServer {
override init() {
super.init()Get["/login"] = { ... } Post["/login"] = { ... }
}
}—
Reply to this email directly or view it on GitHub
#27 (comment).
from swifter.
@glock45 consider Laravel or RoR?
from swifter.
Hi...are u still following the idea to make a Sinatra inspired swift version ?!
When apple finally releases Swift for linux then "swifter" would be perfect for creating micro services
from swifter.
When apple finally releases Swift for linux ... "swifter" would be perfect for creating micro services
+1
from swifter.
@mwelser and @tristaaan Swifter will not work on Linux even after Swift is open sourced and ported because it depends on Foundation, which Apple will not port to Linux or open source.
from swifter.
@sdgandhi we are going to get rid of the dependencies - #60
from swifter.
Basic support for Sinatra routing has been added recently: df24ced
from swifter.
hi guys ( @jchannon @sdgandhi @tristaaan @mwelser @18601673727 @jchannon @jayrhynas @julien-c and others ! )
This thread is the main place for discussing routing mechanism so let me summarise what we already have an what's the bright future :)
With version 1.0.5 we have a support for the following routing mechanism:
Example 1 ( new ):
let server = HttpServer()
server.GET['/books/:id'] = { ... } // For GET http method.
Example 2 ( old - still supported ):
let server = HttpServer()
server['/books/:id'] = { ... } // For any http method.
We also extracted IO part from HttpServer class to HttpServerIO class:
class HttpServerIO {
// socket IO to accept connection {
// delegate request handling to select() function.
// }
...
public func select(...) {
return ([:], { _ in HttpResponse.NotFound })
}
}
class HttpServer: HttpServerIO {
let router: HttpRouter()
...
override public func select(....) {
return router.select(....)
}
}
As you can see the only task for HttpServer class is to expose the routing API and perform the routing. It means everybody can now create a new cool routing DSLs and add is as another MyHttpServer or make an extension for current HttpServer without making huge changes in HttpServer class:
extension HttpServer {
...
}
or
class MyServer: HttpServerIO {
...
}
Below I got examples of the new ideas I've been thinking about:
let server = HttpServer()
server < users << :id = {
}
or
enum Router {
case users( (Int) -> {
})
}
from swifter.
Is it possible to use wildcard/regexp in routes?
Thanks and Happy Holidays!
from swifter.
hi @BeQ
Initially we supported regexps but we removed it :) Wildcard is supported. Please have a look at the example: https://github.com/glock45/swifter/blob/master/Sources/DemoServer.swift#L104
best
dk
from swifter.
Related Issues (20)
- usleep degrades when using Swifter
- Unable to connect to server HOT 1
- tvOS 16 Beta 2 Unable to override the Stub that has same url
- Builds fails when trying to use `Swifter` in XCUITest HOT 3
- 404 Not Found HOT 1
- Building release is extremely slow
- Enhancement request: Swifter to label .wasm files as "application/wasm" when it serves them
- Can the development on this package be sponsored?
- IOS 16.4problem: Restricted network ports are not allowed HOT 3
- How to get post parameters ?
- How to set multiple responses for one endpoint?
- Question for loading index.html + subdirrectories HOT 1
- Support regular expression
- Bind operation not permitted - MacOS - UITests
- Privacy Manifest HOT 6
- HttpServer does not support for multicast
- Release new version from stable branch (Cocoapods)
- How to use the ssl HOT 1
- Does this lib work in iOS for moblie ? HOT 4
- can not use on iPhone
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swifter.