agrafix / Spock

Another Haskell web framework for rapid development
https://www.spock.li
678 stars 56 forks source link

There is no further tutorials than the basic one #98

Open Miguelme opened 7 years ago

Miguelme commented 7 years ago

I think it would be really useful for begginer users if they have at least another tutorial where it shows how to handle a post request including JSON handling since this tutorial (https://www.spock.li/tutorial/) is quite simple and there are no other (at least that are easily accessible). I think it would be wise to guide the user as to where to follow after finishing the previous tutorial.

agrafix commented 7 years ago

I like your request because you explicitly ask for something you'd like to have explained and not just "we need more tutorials"! Therefore I will try to sit down sometime this week and write something. Could you follow the mentioned tutorial well or would you have some improvement suggestions?

Miguelme commented 7 years ago

Thanks for your feedback. I could follow pretty well the tutorial. The only part that I would say is not clear is the following:

Now we will add Spock to our dependencies by opening Spock-example.cabal and adding Spock >=0.11, mtl and text to build-depends in the executable Spock-example-exe section. Next we build everything once: stack build --fast --pedantic.

I think here it could be shown the .cabal as it should be according to this (Just because is overwhelming for begginers). I think maybe display the entire file being displayed here could help a lot.

Thanks in advance.

Anything do not hesitate to contact me, always happy to help with Haskell Development.

flounders commented 7 years ago

It would be nice to see some treatment of getpost and how get and post requests for the same route should be handled as well. The tutorial is great, but looking at the example projects feels like a major leap from where the tutorial leaves you at. I would be happy to contribute and write, but I'm still trying to learn Spock and HTTP at the same time, so right now I don't have much to contribute.

theduke commented 7 years ago

I came here to ask for more docs too.

I think the word tutorial is a bit of an exaggeration. It's really just a 'here is the minimal code to have a running server, and these are the most important types'.

Here are some things that I would love to be explained without the need to dig through code.

essential knowledge for any basic use (should be in a tutorial):

some a bit more advanced knowledge:

Cheers.

flounders commented 7 years ago

Here is a start. It needs a lot more commenting, but these are some fairly simple examples that I hope to enlarge upon later. https://github.com/flounders/spock-examples

brynedwards commented 7 years ago

Hi, when starting to learn Spock, my initial difficulty with looking at funblog was that, by incorporating everything into a complete application, it can be a bit confusing trying to understand specific functionality. In the scotty repository, there is an examples folder showing functionality in isolated examples. I've done a few similar examples for Spock here:

https://github.com/brynedwards/spock-examples/tree/master/examples

While doing these, another issue I found was discoverability. For example, once I found spc_errorHandler in SpockCfg, it was easy enough for me to figure out error handling based on its type signature, but actually finding it took a while of clicking around the different modules in Spock and Spock-core. Maybe a quick reference that mentioned how to do various tasks, e.g. "For error handling see SpockCfg's spc_errorHandler"?

Another example would be actions. Many actions are in Web.Spock.Action in Spock-core, but this wasn't immediately obvious to me, as the only reference to that module in Web.Spock is a line somewhat hidden under the Actions section. Perhaps show the actions in the Web.Spock module documentation, if that's possible, since they're already exported. I can try help with these and more if you'd like.

chris-martin commented 7 years ago

once I found spc_errorHandler in SpockCfg, it was easy enough for me to figure out error handling based on its type signature

sc_errorHandler?

Status -> ActionCtxT () IO ()

It's not at all apparent to me what to do with this. How can such a handler get the error that was thrown?

brynedwards commented 7 years ago

This was where I found the record for error handling. As for handling exceptions in it, I'm afraid I don't know that either; all I found was this mailing list thread about it.

agrafix commented 7 years ago

The handler currently only get's the status code, not the full exception. You could change that with a PR if you like

xanderdunn commented 7 years ago

Very much agree that further documentation would be a great boon. I've had considerable difficulty finding how to deal with POST requests, JSON data, and how to set headers such as CORS compliance.

lpil commented 7 years ago

Hello all

I'm in the process of making a toy application with Spock, for fun and learning. I could try and write up some mini-tutorials on things that seem useful, for example middleware application. Would you be open to PRs for this @agrafix ?

Cheers, Louis

agrafix commented 7 years ago

Sure, that sounds good! Feel free to ask anything if you need help.