Responder Web Framework Mini-course Transcripts
Chapter: Building a RESTful API with Responder
Lecture: Responder core concepts

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's close down our chapter on Responder
0:02 by quickly looking at some of the core concepts.
0:04 Incredibly, what you see on the screen here
0:06 is a complete Responder application
0:09 assuming that you don't count that index file
0:11 that's just the static HTML or dynamic HTML.
0:14 So, what are we going to do to get started
0:16 with a templated HTML page-based view?
0:19 Come in here and create an API from responder.api
0:22 similar to Flask's app.
0:24 We're going to add a route as a decorator
0:26 through api.route and we saw
0:28 that you can even use curly braces like f-string
0:31 like syntax to define places where data
0:34 is passed in the URL.
0:36 Then we're going to use api.template
0:37 and pass the relative file name
0:40 of the template we want to use.
0:41 It assumes that you're talking about the
0:43 template's folder, so within there
0:45 it's the home directory in the index.html file.
0:47 We're also here passing a user key
0:50 which has the value u.
0:52 It didn't really say where u comes from
0:53 but, you know, you get it from somewhere, right?
0:55 And you're passing along values like this that can
0:57 be used inside that Jinja2 template.
1:00 And then, what we do is we just set
1:01 the content of the response.
1:03 It's a mutable object, so we don't return values
1:05 we just change response.
1:07 Gives us a bare one, we set some values in it
1:09 uses that result to generate the page.
1:11 That was for a page backed by a template.
1:14 What if we want a JSON-based API view?
1:17 Well it's pretty similar.
1:18 We're going to have the route again
1:19 and see we're passing the keyword this time.
1:22 And that key word appears in the search methods signature.
1:25 Then, we're just going to create a JSON serializable thing.
1:29 The simplest is probably a dictionary
1:31 or list of dictionaries, things like that.
1:32 And we're going to set the media element right there.
1:35 And by setting media, we're telling it
1:37 here is a JSON object.
1:39 I want you to serialize and send back as
1:41 part of this API response with the content type being JSON.
1:45 That's it, that's Responder!
1:46 Remember, all the key features I told you
1:49 about at the beginning, that are not shown or covered here.
1:52 Web sockets, async capabilities, background tasks.
1:56 All that kind of stuff is in there
1:57 but we don't have time to cover it.
1:58 You can go explore it yourself, it looks really cool.