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

API first development #124

Open
szabgab opened this Issue Jun 2, 2017 · 3 comments

Comments

Projects
None yet
4 participants
@szabgab
Member

szabgab commented Jun 2, 2017

Usually every route ends with a call to template 'some.html', { ... };
It might be more interesting if Bailador made it simple to create an API that returns JSON and on top of that to return HTML pages. So a normal route of Bailador would return a datastructure and the name of a template. Then Bailador would either return only the datastructure as a JSON or would call the template() function with the given template and the data structure.
How can this kind of coding made simple and obvious to use?

I'd go even further. Today with the Microservice architecture being popular, a lot of web applications don't even need to return HTML. Just JSON. Even the 404 and 500 pages are different than in the HTML world. IMHO It would be important to make it very easy to write such applications in Bailador.

@ufobat

This comment has been minimized.

Show comment
Hide comment
@ufobat

ufobat Jun 2, 2017

Member

it reminds me on the respond_to() feature of mojolicious
http://mojolicious.org/perldoc/Mojolicious/Controller#respond_to

i'd say that your Feature requests sounds perfect for the job of a plugin
so you could have some hook, that catches the data retunred from your callback/sub, and passes it to template('template-name.tt'), and this plugin could automatically take the $route-name as template-name

so for the route
get '/foobar' => sub { ....; return %data } t
his plugin should do this for you:
template('foobar.tt', %data)

Member

ufobat commented Jun 2, 2017

it reminds me on the respond_to() feature of mojolicious
http://mojolicious.org/perldoc/Mojolicious/Controller#respond_to

i'd say that your Feature requests sounds perfect for the job of a plugin
so you could have some hook, that catches the data retunred from your callback/sub, and passes it to template('template-name.tt'), and this plugin could automatically take the $route-name as template-name

so for the route
get '/foobar' => sub { ....; return %data } t
his plugin should do this for you:
template('foobar.tt', %data)

@bradclawsie

This comment has been minimized.

Show comment
Hide comment
@bradclawsie

bradclawsie Jun 7, 2017

Does Bailador have a notion of middlewares? Would be helpful for API-style development.

bradclawsie commented Jun 7, 2017

Does Bailador have a notion of middlewares? Would be helpful for API-style development.

@JJ

This comment has been minimized.

Show comment
Hide comment
@JJ

JJ Dec 2, 2017

Contributor

I definitely think API should go first. Most microframeworks don't even bother with HTML, or use some generic templating library for that.

Contributor

JJ commented Dec 2, 2017

I definitely think API should go first. Most microframeworks don't even bother with HTML, or use some generic templating library for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment