PXshadow / weblink

MIT License
41 stars 6 forks source link

Implementing compability #1

Closed ConstNW closed 4 years ago

ConstNW commented 4 years ago

Hi! I found your project very interesting and useful, but i have a questions about your vision of the weblink. Did you make it api compatible with nodejs http-server or similar to fastify framework?

PXshadow commented 4 years ago

Hey! That is amazing to hear that it's been useful 😄. As for vision I've made it similar to Express/Fastify, unfortunately Haxe doesn't support parameter overloading so I can't make the api compatible fully with any of the nodjs libraries. I am still trying to cement a solid api to go forward with, perhaps you would have some input on which one you would prefer?

Example of a POST request relay:

  1. what it currently looks like, I think app.get makes it confusing it also calls the function for post as well.
    app.get(function(request,response)
    {
    switch (request.method)
    {
        case Post:
        switch (request.path)
        {
            case "/":
            response.sendBytes(request.data);
        }
        default:
    }
    });
  2. fixes the confusion of app.get but still a decent amount of boiler plate code to do this.
    app.create(function(request,response)
    {
    switch (request.method)
    {
        case Post:
        switch (request.path)
        {
            case "/":
            response.sendBytes(request.data);
        }
        default:
    }
    });
  3. express way get and post are defined by app callback functions, but still uses switch statement for path.
    app.post(function(request,response)
    {
    switch (request.path)
    {
        case "/":
        response.sendBytes(request.data);
    }
    });
  4. all of the way everything gets defined upfront no more switch statements. but doesn't easily allow query() calls inside where you could get parameters via the url, example: "/search?text=hello%person" = (path = "/search" and query = {text: "hello person"}).
    app.post("/", function(request,response)
    {
    response.sendBytes(request.data);
    }
PXshadow commented 4 years ago

@ConstNW update I picked option 2. I hope it works well let me know what you think, I also added some features like query() for url params and serve static files.