-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Help me design / write a generic HTTP routing helper library for the http_s struct. #155
Comments
Hi, Thank you so much for both your interest in contributing and detailed suggestion. That's a lot of beautiful work that you did and a lot for me to go over. My biggest things to note:
Development Repo UpdatesPlease allow me to point out that edge development for the facil.io functionality, including the HTTP layer, is now performed in the repo: https://github.com/facil-io/cstl The new repo represents the transition to version 0.8.x. DependenciesThe project avoids external dependencies when possible, especially dependencies that might raise licensing issues. For this reason RegEx cannot be accepted (unless we roll our own and the RegEx Specification License allows us to do so while licensing our code under MIT / ISC). For now, I suggest that we limit our URL section parser to glob matching that is already implemented, or perhaps rolling our own slightly expended approach. By the way, does APIUser experience is highly values in the facil.io approach. Everything should be easy. For this reason, I would like to minimize the number of possible functions and provide named arguments for functions with more than 3 or 4 arguments. Basically I hope to have as little as a single function that controls the router: typedef struct fio_http_router_s fio_http_router_s;
/**
* Creates a route to URL and returns a pointer to a router object starting at that URL (sub-router).
*
* The sub-router allows calls to `fio_http_router_map` to treat `url` as the root of any new routes.
*
* The sub-router may be discarded or ignored, but it MUST NOT be freed manually (as it belongs to the main router object).
*/
fio_http_router_s * fio_http_router_map(fio_http_router_s *, const char * url, fio_http_router_options_s opt);
/** named arguments helper for the `fio_http_router_map` function. */
#define fio_http_router_map(router, url, ...) fio_http_router_map(router, url, (fio_http_router_options_s){__VA_ARGS__})
/* and, of course, init/destruct functions: */
fio_http_router_s * fio_http_router_new(void);
void fio_http_router_free(fio_http_router_s *);
void fio_http_router_destroy(fio_http_router_s *);
#define FIO_ROUTER_INIT {0} The options passed should include callbacks for The As for the content-type property as a router controller – I think that's a super interesting idea, but in general I haven't seen much use for it in the wild. If this is a use-case you encountered, we can definitely add it while keeping the Naming ConventionsPlease note that all names in facil.io use snake_case and types have a designated suffix that depends on what they refer to (i.e., We avoid the To maintain name space integrity and avoid the risk of name collisions (especially with possible user code), the names of types and functions should follow the The library is always So, in this case, I would expect Argument TypesThe moment we accept dynamic URL segments, we need to discuss the types we will use to store this data and how it would be made available. I suggest that we adopt the Again, thank you so much and I hope we can make this work :) |
Okay, no problem.
I'm thinking of PCRE regex, but I'm not aware of the license issues. I don't think including a third-party library from the system (without providing the source) causes license problems. this library is not embedded in the source code, its just a compilation dependancy. (look in haproxy, embedding PCRE it juste changing compilation line https://github.com/haproxy/haproxy/blob/8427c5b5421a93ee29170fb6ca3093478acd7ab7/Makefile#L770)
You can find the
We chose the There are other examples of routers:
I absolutely agree. And a good documentation with many examples will be welcome. The minimum code for using my proposition (disregarding naming, which will be changed later) is:
This contains the minimum information to design a simple project. Other functions are used for advanced usage. Look at the example at the end of my previous post. Perhaps the functions exposed in the API should be separated into two parts. One part that presents simple and concise functions that allow handling most simple projects, and another part that presents advanced functions that also allow handling complex projects.
Sub-routers are strongly used to configure complex applications with inheritance, like this: The main router splits the application into 4 parts, processed by 4 teams:
Note, I've already seen this case at a client's (a very large publicly traded company). Each team handles a part of the application, and the routing was done by the application server (old C technology). Its current usage with other framework of other languages.
Content-type based routing is necessary for compatible APIs. POST with JSON is processed by a specific handler, while POST with form-data is processed by another one.
NULL content-type is handled. Alternative functions without the content-type parameter could be exposed (but this would be one more function).
Okay, no problem. It's a detail to rename all of this.
Absolutely, for me, the most important thing is defining an API, and then types. Obviously, types used by the API are different from runtime types, which must be optimized for speed. All the router/subrouter must be solved as unique descriptor in a sort of compilation phase. Quickly, I'm thinking of some TREEs with one root per METHOD. Each tree node contains:
|
Closing, discussion moved to: facil-io/cstl#26 |
Are you yet interested by this subject. Doing C HTTP framework is one of my favorite subject with c10k problem and asynchronous design in C
I just see your project, and router design is an interesting subject. I start to brainstorm about design. the following is preliminary and not terminated.
And exemple usage (generated by IA) :
Are you interested by this job ? can I continue the brainstorm ?
The text was updated successfully, but these errors were encountered: