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