RESTful and HTTP APIs in Pyramid Transcripts
Chapter: Web application building blocks
Lecture: Pyramid building blocks

Login or purchase this course to watch this video and the rest of the course contents.
0:02 Before we can write our first service, we should have a high level of view of all the moving parts of the building blocks of Pyramid.
0:11 I find in web apps in general they are even harder to work with, than say just standard other libraries
0:17 because a lot of parts have to fit together often via conventions, configuration files, main app initialization files,
0:24 views, templates, static files and so on. So we're going to try to cover those things and show you how they all fit together
0:31 and then we'll start writing some code around it. So what are these building blocks?
0:36 First of all, we're going to need to take a url and map it to some code, some behaviors in our app, so the first thing we can talk about are routes,
0:43 so routes take a url pattern and map them to views, some web frameworks use regular expressions for these,
0:51 and I don't think that's a great way to do it, right, these regular expressions can be really tricky,
0:57 they're powerful but they're also quite complicated and error prone to see why something may or may not map to a particular url.
1:03 Thankfully, in Pyramid, there's a really powerful and simple way to do this, and if we need what regular expressions provide,
1:10 we can add on something like constraints via a regular expression. Views, so views are the functions or the code that runs
1:18 once a request has been routed, and figure out which view it's suppose to go to, all the request data is passed to us, that could be the post body
1:26 that could be the url, a query string and many many more things. Now notice also have a.k.a controllers, Pyramid speaks
1:32 in this template view design pattern language, but it very much matches the pattern of what's more generally known as model of view controller,
1:42 so if you're coming from an mvc design way of thinking I'll also put those words here, so views are the functions
1:48 that run in Pyramid syntax or nomenclature, and these would be called controllers. And we also have templates so once the view is run,
1:57 it's gotten some sort of data, presumably, and it wants to show that to a person or transform that
2:03 into say an xml rss feed to send off to a machine, or even turn into json. Templates are a way to take HTML structure
2:12 and pass a bit of data to it and it will transform it into HTML, we don't use this a ton in services, we use this all the time in web applications.
2:22 So if you have a web page for documentation that's sort of the front part of your service,
2:27 you're going to care about this, if you're just sending json, the thing that we'll be working with is not so much templates but renderers.
2:33 And these renderers take our data and transform it just some sort of plain text thing like json or xml or something like that.
2:41 We also have models, this is the data taken, created by the view and passed either to the template or to the renderer
2:47 to be turned into text for the users, and we have static files and a special way to deal with static files
2:53 again services probably care less about this, but you could theoretically redirect to a static file
2:59 with all of its cashing and support and things like that, and we also have configuration, any real service has database connection strings,
3:06 service API strings, things like what's your Stripe credit card API key if you're going to be a credit card service
3:15 it's going to do some sort of charge for your web application or your web app, so we'll see there's a lot of support for configuration files
3:22 as well as various use cases for these configuration files, like different settings for dev, test and production.


Talk Python's Mastodon Michael Kennedy's Mastodon