Open Nub opened 12 years ago
This is an idea that should absolutely become part of CocoaHTTPServer. I've seen others implement similar extensions in the past:
Blackbox (https://github.com/mattpat/Blackbox) was written on top of version 1.X of CHS. RoutingHTTPServer (https://github.com/mattstevens/RoutingHTTPServer) is more recent.
I've been meaning to add something like this into the repository. Probably adding it as an optional extension.
Take a look at RoutingHTTPServer and tell me what you think of it's architecture. (I haven't had a chance to look deeply into it yet.)
-Robbie Hanson
On May 9, 2012, at 8:36 PM, Zach Thayer wrote:
Hi Robbie!
I was looking into web services for OBJ-C recently and someone mentioned this, after I had found froth kit, I was deciding to go and try to modernize froth kit, but it was a mess and super old. Gladly I was able to find this awesome project which seems to be nice light weight and active!!
So now my presentation I worked on an awesome sub Class of HTTPConnection and added blocked based routing! It makes writing a server crazy simple now! I would love to have a chat and see where you are and how we can move all of CHS more in this direction, next I was going to add a way to link in automatic session management and basic user logins, I'm going for a lean and lightweight webstack for making api's and w/e else you can think of.
So without further ado here is how my class works https://gist.github.com/2650862
And here is it's current implementation https://gist.github.com/2650888
I would love for this to become part of CocoaHTTPServer and maybe influence it's future! I look forward to talking with you!
Reply to this email directly or view it on GitHub: https://github.com/robbiehanson/CocoaHTTPServer/issues/23
Hmm I did not know, however after a brief look through at, what time is it right now? 3:30am ack. Umm well i should review it further, but from what I see I have implemented nearly the same exact thing in ~230lines of code and a single subclass of HTTPConnection and a slight external mod of HTTPMessage. Mine is meant to me as simple as possible, it allows for regex without any special characters to signify it. I do plan to continue mine forward, or work with someone on a awesome solution, but I'll have to do some more reviewing first.
My goal was to add a routing layer without altering CHS and keeping it as simple as possible, which I managed to do :)
I'd appreciate any feedback :)
I would love to see a capability like this brought into the main project. I'll leave it to others to determine how best to implement it, but if there is anything useful in my extension you are welcome to it. I've been using the code to drive a DLNA media server for about a year and been pretty happy with it.
Hey matt thanks for the response! Your implementation does look rather swell, however I feel if CHS was target a bit more to such solutions we could optimize it all and minimize the source footprint, like tailoring HTTPMessage or tweaking the original design in some way to not have to layer in a bunch of new code. Perhaps this router or yours or something new all together replaces a module, I am not sure.
Robbie, if you get some free time to have a chat let me know, I'd be interested in helping to design and implement a solution that makes everyone happy :)
I think we should all start by compiling a list of features we would like to see in future versions of CHS.
Here is my list, somewhat in order of preference.
Very good. Thats what I needed for a prototype I'm developing.
Glad I could help, let me know if you have any suggestions/changes
I forked your gist and pushed an update. I had the problem, that when adding two routes foo
and foo/:id
, the app sometimes crashed when calling /foo
. This was because it matched the route foo/:id
for the requested url /foo
.
Now I added a feature, that the routes will be evaluated in the order they have been added.
Oh, awesome! And thanks for the fix! If I ever get free time again I'm going to fork this project and migrate it in.
Hi Robbie!
I was looking into web services for OBJ-C recently and someone mentioned this, after I had found froth kit, I was deciding to go and try to modernize froth kit, but it was a mess and super old. Gladly I was able to find this awesome project which seems to be nice light weight and active!!
So now my presentation I worked on an awesome sub Class of HTTPConnection and added blocked based routing! It makes writing a server crazy simple now! I would love to have a chat and see where you are and how we can move all of CHS more in this direction, next I was going to add a way to link in automatic session management and basic user logins, I'm going for a lean and lightweight webstack for making api's and w/e else you can think of.
So without further ado here is simple server using my Routing class
And here is it's current implementation https://gist.github.com/2650888
I would love for this to become part of CocoaHTTPServer and maybe influence it's future! I look forward to talking with you! I would also like to inform you, this was whipped together, so there are still some things to resolve, and bug test. Such as freeing the yucky global used to store the blocks and their routes. But this can all be addressed :) It may also be useful to note the return types currently supported by blocks are NSString, NSData, NSDictionary, NSArray, the later 2 will be serialized using NSJSONSerialization.