How to use the Documentation first code?


#1

um… I am a python novice and i never used any web api framework, but i want to learn apistar, and i don’t know how to learn apistar, i see this Documentation code :

from apistar import App, Route


def welcome(name=None):
    if name is None:
        return {'message': 'Welcome to API Star!'}
    return {'message': 'Welcome to API Star, %s!' % name}


routes = [
    Route('/', method='GET', handler=welcome),
]

app = App(routes=routes)


if __name__ == '__main__':
    app.serve('127.0.0.1', 5000, debug=True)

and use curl http://127.0.0.1:5000/ in my terminal get return, Now i can’t understanding why the name is None, What command should I use to Incoming parameters to name, and run return {‘message’: ‘Welcome to API Star, %s!’ % name} this code.

My English is bad, maybe Unclear description, i just want to know how to use curl to pass in parameters and output name


#2

Did you try this one? — http://127.0.0.1:5000/?name=ueane


#3

Apistar might be a bit of a challenge if it is the first framework you are learning. I’ve been writing python non-professionally for 7 years and am constantly reading the source code and looking up the documentation for the libraries it leverages. It’s not really stable yet and Tom has done rewrites before, so you could find the rug gets pulled out from under you, and without experience to fall back on you could struggle to get your code updated. You also don’t have a lot of extensions at your disposal, so if your goal is to write apps you could find yourself spending more time building out the missing functionality that other frameworks provide.

I’m not try to turn you off to Apistar, I irrationally love it. If for you it is about learning then digging into this framework’s internals is a good exercise. Due to the lack of documentation it really is the best way to learn Apistar. I have spent many an hour just flipping through the github. This forum is good if you have that specific question or use case, but since the rewrite from 0.3.9 to 0.4.x a lot of the older posts and code will be irrelevant.

If your goal though, like I said above, is to build your dream app then you might want to consider something that you can get a book or a course on like Flask, Pyramid, or Django.

If you want to improve your python chops then I have to recommend the Fluent Python book by Luciano Ramalho, and if you just need some recipes for things or want to explore a little bit of the standard lib without the confusion of the python doc examples then you should pick up David Beazley’s Python Cookbook.


#4

yeah, this can work, thank you ~


#5

Thank you very much for your advice~ This is really helpful for me.