YouTube2Text

API Design and Architecture - Backend Engineering Intro (1 Hour) — Transcript

by Caleb Curry · 8,377 words · 1,272 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Hey, what's going on everybody? It's
  2. 0:01Caleb and welcome to your video on API
  3. 0:03concepts, design, and architecture. I'm
  4. 0:05really excited for this because this is
  5. 0:06the start of a series of videos on
  6. 0:08application development, backend
  7. 0:10development, API development. We're
  8. 0:12going to talk about a lot of concepts,
  9. 0:13but we're also going to follow up with
  10. 0:14hands-on exercises, and building out
  11. 0:16applications. So, first thing I wanted
  12. 0:18to mention is you'll want to check for
  13. 0:20the playlist link so you can watch
  14. 0:22through all of these videos. Now, this
  15. 0:24is a pretty long one. It's going to set
  16. 0:25the foundation. So, there's a couple of
  17. 0:26things I want to get out of the way at
  18. 0:28the beginning. So, I already mentioned
  19. 0:29the playlist, but I also want to mention
  20. 0:32the notes. I have extensive notes for
  21. 0:33this lesson and some of the upcoming
  22. 0:35lessons as well. So, you will want to
  23. 0:36check that out. I'll have a link down
  24. 0:38below. So, those notes act as a
  25. 0:39companion for these lessons. It'll have
  26. 0:41everything we're talking about,
  27. 0:42different code examples, references, and
  28. 0:45additional information that'll go along
  29. 0:46really well with these lessons.
  30. 0:49The other major thing is that some of
  31. 0:50these lessons will be concepts, some of
  32. 0:52them will be hands-on. You definitely
  33. 0:54want to follow up the concepts with
  34. 0:56hands-on material so you can solidify
  35. 0:58what we're talking about here. It's very
  36. 0:59critical that you follow along and
  37. 1:00actually build APIs so you know how to
  38. 1:03take what we're talking about here and
  39. 1:04apply it to the real world. And then the
  40. 1:06last thing, this isn't really an
  41. 1:07advanced series, but we're not going to
  42. 1:09start from the absolute beginning. So
  43. 1:11we'll introduce APIs without much prior
  44. 1:14knowledge, but if you need additional
  45. 1:15computer science principles,
  46. 1:18I have a fundamentals course which I'll
  47. 1:20have a link down to below. This is not
  48. 1:22mandatory, but if you find that the
  49. 1:24material here is going a bit fast, I'd
  50. 1:25recommend you go through that first. Oh,
  51. 1:27and one last thing, timestamps.
  52. 1:34We're going to cover a lot of
  53. 1:35information, so you'll want to use the
  54. 1:37timestamps available on the timeline or
  55. 1:38in the description to jump to whatever
  56. 1:40section you need. This will be handy if
  57. 1:42you want to reference certain sections
  58. 1:43later, or if you don't get through the
  59. 1:44full lesson in one go, you can jump back
  60. 1:46to where you left off. So, a while ago
  61. 1:48here on YouTube, I did a REST APIs in
  62. 1:501hour video, and I think this was a
  63. 1:52pretty good introduction, but this
  64. 1:53video's focus is going to be a bit
  65. 1:55different. First, we're going to go in
  66. 1:56more depth. We'll cover the same
  67. 1:58material with a lot of additional
  68. 1:59information and cover more material in
  69. 2:01this lesson because this is going to be
  70. 2:03dedicated to just all of the API
  71. 2:05concepts you need to know to be a
  72. 2:06software engineer. We'll talk about the
  73. 2:08different types of APIs. You might be
  74. 2:10coming here looking for REST API
  75. 2:11information, which is the majority of
  76. 2:14what we're going to talk about, but
  77. 2:15there are other API types as well. So
  78. 2:17we'll talk about how REST APIs are
  79. 2:18different than these other types.
  80. 2:20Additionally, we're going to bring in
  81. 2:21more system design concepts.
  82. 2:26So this gets into a little bit more of
  83. 2:28dealing with different servers and how
  84. 2:30to architect your API in a way that it
  85. 2:32can be scalable. So we want to build
  86. 2:34scalable systems
  87. 2:41that can support many many users. So, if
  88. 2:44you're just getting started, some of
  89. 2:45these things you might not worry about
  90. 2:46because you're just trying to build your
  91. 2:48first API. We're going to do that, but
  92. 2:50then we're going to go deeper and talk
  93. 2:52about more stuff you should know. We'll
  94. 2:53also talk about pageionation,
  95. 2:55authentication, versioning, and various
  96. 2:58other intermediate and advanced topics
  97. 3:00when it comes to building out
  98. 3:02applications. So, I'm very excited for
  99. 3:04this video. Consider this to be the
  100. 3:05foundation
  101. 3:08that you're going to build the rest of
  102. 3:10your knowledge on when it comes to
  103. 3:13application development and APIs. So, I
  104. 3:16want to introduce you to everything you
  105. 3:17need to be successful. So, we're going
  106. 3:18to cover a lot of different things in
  107. 3:19this lesson. By the end of this video,
  108. 3:21you're not going to be an expert on
  109. 3:22everything, but you'll have a much
  110. 3:23better idea of everything you should
  111. 3:25know, and we'll continue to discuss all
  112. 3:27of those different topics in future
  113. 3:29lessons. So, let's first start talking
  114. 3:31about what an API is, what it stands
  115. 3:34for.
  116. 3:38So, this stands for application
  117. 3:40programming interface.
  118. 3:43And this allows us to build applications
  119. 3:46that talk to each other.
  120. 3:51So when you hear the term interface, you
  121. 3:53should think of the surface area of
  122. 3:56potential interactions for an app. So
  123. 3:58let's say we build this app here.
  124. 4:02This app might work with a database and
  125. 4:04do all these complex things.
  126. 4:06But we don't just give everybody access
  127. 4:08to the database. We give specific things
  128. 4:11that the user can do. For example, we
  129. 4:13could get some data or we could delete
  130. 4:14some data. And these different things we
  131. 4:17can do that concept is called an
  132. 4:19interface. And it allows us to interface
  133. 4:22with other applications. So we might
  134. 4:24have a different app over here.
  135. 4:26And we can interact with app one from
  136. 4:29app 2 because app one has an API.
  137. 4:34So these two apps could be two
  138. 4:36completely different apps. For example,
  139. 4:37I might be building some calendar app
  140. 4:42and I'm using Google Maps API.
  141. 4:46Basically asking, hey, how long would it
  142. 4:48take to get to my appointment? And the
  143. 4:51API gives me back a response.
  144. 4:57So basically, I just enhanced the
  145. 4:59functionality of my app by using some
  146. 5:01other apps API. This is a very common
  147. 5:04structure. Another very common structure
  148. 5:06is instead of using a completely
  149. 5:08separate API, I might actually split my
  150. 5:10app out into backend front end. So
  151. 5:14logically the same product or same
  152. 5:17purpose but two separate code bases. And
  153. 5:20this front end will just make API
  154. 5:22requests to my backend. This backend can
  155. 5:25then grab data from the database or make
  156. 5:27sure that whoever is asking for this
  157. 5:29information is authorized to ask for
  158. 5:31that information. So we're not just
  159. 5:33giving data out to anybody. And then
  160. 5:34once the back end does all the
  161. 5:35processing and whatnot, it sends the
  162. 5:37data back to the front end. The front
  163. 5:40end can then display it all pretty and
  164. 5:42cute on a web page. So this is the other
  165. 5:45major structure that you will see APIs
  166. 5:47for in this situation. You can still
  167. 5:49think of these as two apps. We have a
  168. 5:50front-end app and a backend app. They're
  169. 5:52just working together to provide a
  170. 5:55single product.
  171. 5:58So this is different than if I use some
  172. 5:59third party API to enhance my app's
  173. 6:02capabilities. But both of these are
  174. 6:03possible. Doesn't really matter. The
  175. 6:05whole idea with an application
  176. 6:06programming interface is you can do
  177. 6:07whatever you want. Basically, we create
  178. 6:09an app and we expose different
  179. 6:12capabilities to the outside world to
  180. 6:14interact with our app. So that is the
  181. 6:16general idea around APIs. So this is
  182. 6:18what we're building, right? But there
  183. 6:20are actually different types.
  184. 6:23So these types of APIs, that's what I
  185. 6:25want to talk about now. The main one
  186. 6:28we're going to start working with is a
  187. 6:30REST API. So, R S where you might see
  188. 6:33RESTful
  189. 6:35which is an API that follows REST
  190. 6:37principles. So, that's probably the
  191. 6:39first thing you should become familiar
  192. 6:41with, but we're going to compare it to
  193. 6:42some of the other options out there. So,
  194. 6:44let's talk about the types of APIs. And
  195. 6:47I'm going to talk about some of the most
  196. 6:48common ones, but there are other ones
  197. 6:50I'm sure. So, the first one we just
  198. 6:52mentioned
  199. 6:56would be a REST API. REST stands for
  200. 6:59representational state transfer. So it's
  201. 7:02some way to transfer state between apps.
  202. 7:05REST will use HTTP. So we'll be able to
  203. 7:07do this inside of a browser and it works
  204. 7:10with JSON. JSON is an object notation.
  205. 7:13So this describes how we structure the
  206. 7:15data that we send over the line. Now
  207. 7:17another one you might hear is SOAP.
  208. 7:21Now I never use SOAP. My temptation to
  209. 7:23make some stupid joke about real world
  210. 7:25soap is unbearable. This is an
  211. 7:28alternative to rest.
  212. 7:35This was used a lot more in earlier
  213. 7:38applications. So you might see this for
  214. 7:39legacy systems
  215. 7:42or enterprise systems.
  216. 7:46A big difference with these SOAP APIs is
  217. 7:48that they use XML, which is you can
  218. 7:51imagine JSON, but 10 times more annoying
  219. 7:54and difficult to work with. Then you
  220. 7:56have XML. So if you're building a new
  221. 7:58system, I wouldn't use SOAP, but you
  222. 7:59should definitely be familiar with it,
  223. 8:01at least an idea. So if you do come
  224. 8:03across a SOAP API, you're not like, "Oh,
  225. 8:05what's this?" That'll be important if
  226. 8:07you're building a new system that
  227. 8:08integrates with an old system. that old
  228. 8:11system might not have a REST API and you
  229. 8:13might need to use SOAP. Even though
  230. 8:15you're building a new system, the
  231. 8:17interaction with the old system, you
  232. 8:19need to adhere to the API of the old
  233. 8:22system. So say this is the old system,
  234. 8:24you might be making new upgrades and
  235. 8:26instead of completely replacing
  236. 8:29the old, you might just make a new app
  237. 8:34that integrates with the old app
  238. 8:37providing new features or new interfaces
  239. 8:40for users.
  240. 8:42But for this you might need to use
  241. 8:44whatever the old app uses for
  242. 8:46interaction. So that might be a SOAP
  243. 8:48API. Next up we have GraphQL.
  244. 8:53Now, if you're familiar with databases,
  245. 8:55you might be familiar with SQL. And this
  246. 8:57is structured query language. GraphQL
  247. 9:00works in a very similar way, but it's
  248. 9:02not to interact with a database
  249. 9:03directly. Rather, it's to interact with
  250. 9:05a backend.
  251. 9:07So, in this situation, instead of
  252. 9:09exposing multiple endpoints,
  253. 9:17this would be the traditional rest
  254. 9:18approach.
  255. 9:27What we'll do instead is we'll just
  256. 9:29create a backend that is a very pretty
  257. 9:31back end that has one GraphQL endpoint
  258. 9:35that the front end can connect to
  259. 9:39or the other app can connect to and then
  260. 9:41the front end here does the decisions on
  261. 9:45what it wants.
  262. 9:49So you can think of it as the front end
  263. 9:50providing a query to the back end and
  264. 9:52then the back end provides the
  265. 9:54appropriate response. So this is a
  266. 9:56really common thing. Usually I would
  267. 9:58recommend people learn this. So if you
  268. 9:59already are familiar with REST, you
  269. 10:01should probably get some experience with
  270. 10:02GraphQL. However, if you're brand new, I
  271. 10:05would recommend first learning REST.
  272. 10:06Next up we have GRPC.
  273. 10:10Now you may have heard of RPC before,
  274. 10:12which is remote procedure call.
  275. 10:16You can think of this as a way to
  276. 10:17execute things
  277. 10:21on the back end. But when we prefix it
  278. 10:24with G, this is a specific protocol, the
  279. 10:27Google RPC protocol. Now, many people
  280. 10:30are going to say that this G stands for
  281. 10:32Google.
  282. 10:34However, I think officially this stands
  283. 10:36for
  284. 10:41GRPC, remote procedure call.
  285. 10:45So, it's just a recursive acronym.
  286. 10:47You'll see this quite commonly in
  287. 10:48different technologies.
  288. 10:50But ultimately, when you see gRPC, you
  289. 10:52can think Google remote procedure call.
  290. 10:55And this is a specific type of API that
  291. 10:58uses something called protocol buffers
  292. 11:00or protobuffs.
  293. 11:02So instead of XML or JSON, we'll have
  294. 11:05protocol buffers.
  295. 11:08So this is an approach to serializing
  296. 11:10data that's very effective. It it
  297. 11:12reduces the uh size of the data as much
  298. 11:15as possible, allowing for very fast
  299. 11:17transfers between apps. This is really
  300. 11:19common for micro service architectures.
  301. 11:22So let's say instead of just having a
  302. 11:24front end and a backend, you might have
  303. 11:26all these different components that
  304. 11:28interact with each other
  305. 11:30and all of these work together to
  306. 11:32provide
  307. 11:34the architecture for some app.
  308. 11:40This generally is called a micros
  309. 11:41service architecture and using
  310. 11:43protobuffs is pretty common for this for
  311. 11:45that cross app communication although
  312. 11:47not required. You could just use a rest
  313. 11:48api. So with this you will have files
  314. 11:51that are of the prototype
  315. 11:55not prototype prototype and these
  316. 12:00define a structure for the types.
  317. 12:07So every single app can use these proto
  318. 12:10files to establish the structure of the
  319. 12:13data in their individual apps whatever
  320. 12:16language that might be. So this is
  321. 12:18really great working across multiple
  322. 12:19different languages. We can define all
  323. 12:21of the types with these protoiles and
  324. 12:24there's ways to transfer from a protoile
  325. 12:27into a certain type for whatever
  326. 12:29language you're working in. Now I would
  327. 12:30say those are the main four you should
  328. 12:32be familiar with. You can also use
  329. 12:34things like websockets to interact
  330. 12:36between apps. So you can build a
  331. 12:38websocket API
  332. 12:44and a websocket is a birectional
  333. 12:48channel to communicate.
  334. 12:50So if we have a backend and a front end
  335. 12:54or two apps, they don't have to be
  336. 12:55backend front end. We typically with a
  337. 12:57REST API, we'll make a request to the
  338. 12:59back end and then the back end gives a
  339. 13:01response. But with websockets, the
  340. 13:03backend can also send data directly to
  341. 13:06the front end without a request.
  342. 13:08Basically, the way this works is the
  343. 13:10front end opens a connection
  344. 13:13and then that connection is maintained
  345. 13:20and the communication can then happen
  346. 13:22from either direction as long as that
  347. 13:25connection is maintained. This is really
  348. 13:27common for real time applications.
  349. 13:32So if something happens on the back end
  350. 13:33and we need to immediately tell the
  351. 13:35front end, then you could say this is a
  352. 13:38real time app. For example, a
  353. 13:40communications app such as chat or
  354. 13:44notifications
  355. 13:48and so forth. Anything where the
  356. 13:50communication is initialized from the
  357. 13:52back end. But do keep in mind that the
  358. 13:54front end can also send data to the back
  359. 13:56end as well. So here are some of the
  360. 13:57other types of APIs. You can look up
  361. 13:59others if you want to know more
  362. 14:00information. These are some of the
  363. 14:02things I'm hoping to cover here in this
  364. 14:05playlist or on YouTube.
  365. 14:08So, if you're interested in building
  366. 14:10some of these things, you'll definitely
  367. 14:11want to hit that subscribe button,
  368. 14:13follow along for the journey. And now
  369. 14:15what I want to do for the rest of this
  370. 14:16video is zoom in on this one here.
  371. 14:22REST APIs or as I mentioned you might
  372. 14:25see restful APIs.
  373. 14:29Once you have this down, you should be
  374. 14:31pretty competent in cross app
  375. 14:34communication and then picking up these
  376. 14:35others is going to be a whole lot easier
  377. 14:37because you understand the principles.
  378. 14:38Now the actual way you do it is going to
  379. 14:41be different. So there's some stuff
  380. 14:42we're going to talk about that's
  381. 14:43specific to restful APIs. So
  382. 14:45specifically, we're going to have
  383. 14:48different methods we're going to talk
  384. 14:49about. We're going to have a variety of
  385. 14:52end points.
  386. 14:56We're going to have status codes,
  387. 14:58response codes,
  388. 15:02and we're going to be working with JSON
  389. 15:05data. So if you're not familiar with
  390. 15:07JSON, it's really, really simple. I'll
  391. 15:09show you a very basic example right
  392. 15:10here. right now, right at this moment.
  393. 15:14Not going to delay. Just going to show
  394. 15:16it to you. Okay, it's going to be right
  395. 15:18here. So, JSON stands for JavaScript
  396. 15:20object notation.
  397. 15:23It looks very similar to an object in
  398. 15:25JavaScript. If you haven't used
  399. 15:26JavaScript though, it's no big deal.
  400. 15:28Basically, you're going to open the
  401. 15:30object with a curly brace. Then, you're
  402. 15:32going to have a series of attributes.
  403. 15:33These will be quoted such as name
  404. 15:37and then a colon and then the value
  405. 15:42and then a comma
  406. 15:45and then another attribute quoted
  407. 15:49and then a value such as 30. In this
  408. 15:52case it's not quoted. This supports
  409. 15:54different types here. So we can use a
  410. 15:56string which we showed with Caleb. We
  411. 15:58could use a number.
  412. 16:00We can use a boolean true or false.
  413. 16:03We can have nested objects.
  414. 16:06That's an important thing here. We can
  415. 16:07structure objects inside of other
  416. 16:09objects.
  417. 16:11And we can have arrays. I think we can
  418. 16:13also have null as well, which you can
  419. 16:15count if you want. So if you have an
  420. 16:18attribute and you specifically want to
  421. 16:19say there's no value for that attribute,
  422. 16:24you can use null. Notice that there's no
  423. 16:27quotes here. That would be a string
  424. 16:29containing null. It's just null, the
  425. 16:31keyword. Now, if you're coming from
  426. 16:32JavaScript,
  427. 16:36you might notice some similarities, but
  428. 16:38within JavaScript code, you don't have
  429. 16:40to quote the attributes. And you can
  430. 16:42also use different types inside of an
  431. 16:44object within JavaScript. So, for
  432. 16:46example, you could use a date
  433. 16:50or a function
  434. 16:54or undefined.
  435. 16:56These things are not supported in JSON.
  436. 16:58So it's not a one one two JavaScript
  437. 17:01objects. So I wouldn't even really
  438. 17:03strongly associate this with JavaScript.
  439. 17:05I would just think of it as JSON with
  440. 17:07key value pairs surrounded by curly
  441. 17:09braces. Okay, so we have a pretty decent
  442. 17:11understanding of the structure of our
  443. 17:13data. How do we use the structure to
  444. 17:15build an API? What does a REST API look
  445. 17:17like? Well, some of the things we just
  446. 17:19mentioned, we'll have a method
  447. 17:24for example and these are written in all
  448. 17:27caps. Get this is an HTTP method. So,
  449. 17:30REST API is built on top of the HTTP
  450. 17:33protocol. So, with that, you'll have an
  451. 17:35HTTP method. Get is a very common one.
  452. 17:37This is used to retrieve data from a
  453. 17:40server. And when you go and visit a web
  454. 17:41page, you're actually making a get
  455. 17:43request, even if you're not working with
  456. 17:44APIs directly. And then you'll typically
  457. 17:46have some resource.
  458. 17:50So resource you can think of this as
  459. 17:53here. Let me give you a bunch of other
  460. 17:54abstract names. Entity,
  461. 17:59an item or some database record.
  462. 18:03This is basically the thing that we are
  463. 18:05wanting to interact with. So an example
  464. 18:08of this would be users.
  465. 18:10And that would be something that might
  466. 18:12give us back that same JSON structure we
  467. 18:15saw earlier where we have the person's
  468. 18:17name and their age. I'm going to go
  469. 18:19through the example of comments posted
  470. 18:21on a website. So this could be a social
  471. 18:23media, it could be whatever you want,
  472. 18:25anywhere that you can post a comment.
  473. 18:29So let's say you have a video
  474. 18:33and people can post comments below.
  475. 18:37We need a way to be able to retrieve
  476. 18:39this information from the backend and we
  477. 18:42don't have direct access to the
  478. 18:43database. So it's going to look like
  479. 18:45this. We have the backend.
  480. 18:48The backend stores that data in a
  481. 18:50database.
  482. 18:52We make a request for comments
  483. 18:57and then that backend formats the data
  484. 18:59as we need and gives it to us
  485. 19:03in JSON.
  486. 19:05Once we have this JSON data, we can work
  487. 19:07with it on the front end to format it
  488. 19:09and make it look nice to the user, which
  489. 19:12is how we end up with
  490. 19:15a web page with the post and then the
  491. 19:19comments below it. So that's the general
  492. 19:23workflow. Then when a user goes in here
  493. 19:25and maybe posts a new comment, this is
  494. 19:28going to follow that same pattern, but
  495. 19:30now it's going to make a request to the
  496. 19:32back end with a different method. So
  497. 19:34instead of a get request, we're going to
  498. 19:37do a post request. All right. At this
  499. 19:40point, you have a pretty decent idea of
  500. 19:41what a REST API looks like or how you
  501. 19:44interact with it. You have a method, you
  502. 19:46have some resource, and then you work
  503. 19:49with JSON. That's how you communicate
  504. 19:51back and forth. So how do you grow this
  505. 19:53to then a collection of different
  506. 19:55endpoints? So that's a word you should
  507. 19:57know. You can think of the end point
  508. 20:02as a combination of the method
  509. 20:06plus the path.
  510. 20:09The path here is basically a URL
  511. 20:12describing what resource you're trying
  512. 20:15to interact with or collection of that
  513. 20:18resource. So let's take a look at an
  514. 20:21example with comments. We're just going
  515. 20:23to write out all of the URL structures.
  516. 20:26And you can think of these as basically
  517. 20:30the different interaction points or
  518. 20:32interface
  519. 20:35to your API.
  520. 20:38So these will all probably be prefixed
  521. 20:40with slash. So you start with a slash,
  522. 20:42but you're going to have something
  523. 20:43before that slash, which will be
  524. 20:45whatever your base URL is, the backend
  525. 20:47API URL. So it might be something like
  526. 20:50mysight.comi
  527. 20:52[Music]
  528. 20:56and then it's pretty common to have some
  529. 20:58version in here. So you might be on v2
  530. 21:00or you might be on v1. basically a way
  531. 21:02to create different API versions. Then
  532. 21:04you will have the resource
  533. 21:08and then if you're working with a
  534. 21:10specific instance so not just all of the
  535. 21:12comments but one comment in particular
  536. 21:15then you can pass in an ID.
  537. 21:19Now this is substituted in.
  538. 21:22So when you visit the web page you're
  539. 21:24not going to actually put ID. You'll put
  540. 21:26in a value like five or 105 or whatever
  541. 21:28the ID is for the element the resource
  542. 21:31you're trying to work with.
  543. 21:34So the way you describe that this is
  544. 21:36substituted in. You might see something
  545. 21:38like brackets ID or you might see colon
  546. 21:42ID. The exact notation is irrelevant and
  547. 21:45every framework is probably going to
  548. 21:46have a slightly different structure. But
  549. 21:49the idea is that we need to indicate
  550. 21:50somehow that the user provides in an ID
  551. 21:53to access that element. So for us, we're
  552. 21:56just going to use curly braces ID.
  553. 21:58However, there are some architectural
  554. 22:00designs with the way you structure your
  555. 22:02URLs and your code around the resource.
  556. 22:06So, in this situation, let's say we are
  557. 22:08working with comments.
  558. 22:12Do you work with comments directly or do
  559. 22:15you always work with comments through
  560. 22:18something else such as the actual post?
  561. 22:24So you might have post
  562. 22:27the ID of that post
  563. 22:31and then get the comments for that post.
  564. 22:37This is a different structure where you
  565. 22:39now think of comments as bucketed
  566. 22:41underneath a different resource in this
  567. 22:42case posts. And usually this is going to
  568. 22:45be plural. So posts, id comments. So
  569. 22:49we'll talk about some of these ideas of
  570. 22:51nesting data as there are some
  571. 22:54alternatives where you can use URL
  572. 22:56parameters to query or filter data
  573. 22:59differently. So we'll look at that soon.
  574. 23:01But for now let's go with this approach
  575. 23:02here where we are working with a parent
  576. 23:06resource. We access a specific post with
  577. 23:09an ID and then we can grab all of the
  578. 23:13comments for that post. So let's write
  579. 23:16out some example endpoints. We'll start
  580. 23:17with the method and because we'll often
  581. 23:19have the URL SL API potentially slv1 or
  582. 23:23v2 I'm not going to put that every
  583. 23:25single time. You can just think of that
  584. 23:26as copied on all of these. So all we'll
  585. 23:29have is slashposts
  586. 23:32slash
  587. 23:36id slash comments.
  588. 23:40So this is the endpoint for retrieving
  589. 23:43all of the comments on a specific post.
  590. 23:46So we have some video. This video has
  591. 23:48the ID of 1 2 3 and it has a series of
  592. 23:51comments down here. The API endpoint to
  593. 23:55retrieve this information
  594. 23:58would be posts 1 2 3
  595. 24:02comments.
  596. 24:04So this is the URL you would use to
  597. 24:06access all of the comments for the post
  598. 24:08with the ID of 1 123. Now the next
  599. 24:10method we're going to look at is post.
  600. 24:11This is how you add data. Now don't be
  601. 24:13confused because we're talking about a
  602. 24:15resource posts.
  603. 24:18This is referring to posts on some
  604. 24:20social media platform like a video post.
  605. 24:24Then we also have post which is an HTTP
  606. 24:28method that means to create. That's
  607. 24:30usually used to add new data. So when we
  608. 24:34come up here and we say post, we're
  609. 24:35talking about the method
  610. 24:38and we're going to create a new comment.
  611. 24:42So it'll be the same exact URL
  612. 24:44structure. The only change here is the
  613. 24:47method that we used. So the method is
  614. 24:49used to tell the server what we're
  615. 24:51trying to do. Because we're adding some
  616. 24:53new data, we will need to attach the
  617. 24:55comment
  618. 25:00data itself in the body.
  619. 25:05So when you make a request, you'll have
  620. 25:07headers and you'll have the body.
  621. 25:11So that's where the actual JSON goes.
  622. 25:16So when we get some hands-on practice
  623. 25:18with this, if you've never done this
  624. 25:19before, I'll show you exactly what I
  625. 25:20mean. So that's going to be important
  626. 25:22anytime we're adding new data because
  627. 25:24the URL itself doesn't give enough
  628. 25:26information. It doesn't say what the
  629. 25:28comment we're actually posting says. So
  630. 25:30we need to include the actual comment
  631. 25:32content and we do that in a separate
  632. 25:33section called the body. All right. So,
  633. 25:36you have a video post, you have comments
  634. 25:38on here, and we know how to get them
  635. 25:39all, but there might be a specific
  636. 25:41comment. And when you create this
  637. 25:43comment, that comment is going to have
  638. 25:45its own ID. Let's just say it's 321.
  639. 25:49Well, to access this comment, if it has
  640. 25:52a unique ID,
  641. 25:57we don't need the parent ID. We don't
  642. 26:00need to know what the video ID is. So we
  643. 26:04can access this without the nesting of
  644. 26:07the post. So it'll look something like
  645. 26:09this. Get slash comments
  646. 26:14slash
  647. 26:16id. So if we made that concrete it would
  648. 26:18be slash comments
  649. 26:21slash 3 2 1. And that'll give us the
  650. 26:24comment content.
  651. 26:27And most likely it would have the post
  652. 26:29ID as well as part of that data. So we
  653. 26:31could associate it with a certain post.
  654. 26:33So if we needed, we could use that to
  655. 26:35figure out what video it goes on. So
  656. 26:37let's just add some notes here. So this
  657. 26:39is to get all the post comments.
  658. 26:46Add a comment to a post
  659. 26:50and then grab a specific comment. Next
  660. 26:53up, the next method we're going to learn
  661. 26:55about is put. This is used to replace or
  662. 26:59update some data. So if we're going to
  663. 27:01edit our comment, we can use a put
  664. 27:03request. Again, for all of these that
  665. 27:04are working with a specific comment, we
  666. 27:06don't need the parent post. So we can
  667. 27:09just say comments
  668. 27:11slash id. So notice these are the same
  669. 27:14URL similar to get and post. The only
  670. 27:17thing differentiating them is the method
  671. 27:19used. So this will replace or update
  672. 27:26comment.
  673. 27:27Now there's another type of request we
  674. 27:31can make which is a patch request
  675. 27:34which works pretty similarly but there's
  676. 27:36some key differences here that you need
  677. 27:37to understand. So the URL will be the
  678. 27:40same.
  679. 27:45This is going to partially update.
  680. 27:48So what that means is with patch if you
  681. 27:50had some
  682. 27:52document
  683. 27:54and you had multiple things you wanted
  684. 27:55to change in it with a patch you could
  685. 27:57just select one of these things and
  686. 27:59change it.
  687. 28:01With a put request you will take the
  688. 28:03entire information make some changes
  689. 28:08and send the entire information back. So
  690. 28:10you're basically replacing the document.
  691. 28:13It's going to be the same idea here with
  692. 28:14comments. If we're using a put request,
  693. 28:17we need to take the full comment, make
  694. 28:19the changes, and then send the full
  695. 28:20comment back. With patch, we can
  696. 28:22selectively change attributes of that
  697. 28:24comment. So, this really only makes
  698. 28:26sense if a comment has multiple
  699. 28:29attributes. So we might have a comment
  700. 28:31ID,
  701. 28:34a post ID, the actual comment content,
  702. 28:39maybe it's a boolean whether this is a
  703. 28:40reply to somebody,
  704. 28:43maybe there's a boolean on whether it's
  705. 28:45a pinned comment. And basically with a
  706. 28:47patch, we could update any one of these
  707. 28:49attributes individually. But with a put,
  708. 28:51we're going to take all of the
  709. 28:53information.
  710. 28:56again we'll change some piece of it and
  711. 28:59then we'll give the entire document back
  712. 29:01replacing the old one. So logically
  713. 29:04we're still updating the data. The ID is
  714. 29:06going to stay the same
  715. 29:12but the way we're updating the content
  716. 29:14is by replacing it completely. So one
  717. 29:17very important thing about updates is
  718. 29:19that they should be item potent.
  719. 29:25And this is a fancy word to basically
  720. 29:26say if you execute that update multiple
  721. 29:29times, the end result should be the
  722. 29:31same. If we replace the document a 100
  723. 29:33times with the same information, we
  724. 29:35still have the same end result. And
  725. 29:37that's exactly why this comment ID has
  726. 29:39to stay the same because if we were
  727. 29:41giving it a new ID, we're creating a
  728. 29:42different comment every single time.
  729. 29:44This is important for accidental
  730. 29:46resubmissions.
  731. 29:49We could submit an update multiple times
  732. 29:57and that's not going to break anything.
  733. 30:00But if we did a creation, if we did a
  734. 30:02post multiple times, we're going to
  735. 30:04either get an error or accidentally
  736. 30:06create duplicate data. So a post is not
  737. 30:09supposed to be item potent. Now this
  738. 30:12attribute is something that you need to
  739. 30:14enforce in your code. So you can code
  740. 30:17these to do whatever you want. You could
  741. 30:19make a postdelete data. You can make a
  742. 30:21get update data. That's all up to you on
  743. 30:23the back end. But these are standards
  744. 30:25and a specification for a reason. People
  745. 30:27adhere to these because you can have
  746. 30:29implicit meaning behind these words. So
  747. 30:31when we're talking about updating data,
  748. 30:33it should be known to be item potent.
  749. 30:37So, we're not going to be replacing the
  750. 30:38ID of the thing we're updating. Next up,
  751. 30:41we have delete.
  752. 30:44It's pretty tough to figure out what
  753. 30:45this one's going to do.
  754. 30:49Again, it's going to be the same path
  755. 30:51because we're referring to a specific
  756. 30:53comment.
  757. 30:55And that will remove the comment. Now, I
  758. 30:57want to show you a couple more examples.
  759. 30:58What if we wanted to reply to a comment?
  760. 31:01In this situation, we would have a
  761. 31:02comment that in a way depends on another
  762. 31:06comment. So we would need to know
  763. 31:10information about the parent comment.
  764. 31:14Who are we replying to? So the way we
  765. 31:17would structure something like this
  766. 31:20would probably be a post because we're
  767. 31:22creating a new comment and then we would
  768. 31:24do slash comments
  769. 31:27slash id
  770. 31:30and then we could have a new path such
  771. 31:31as
  772. 31:33reply and this could reply to a comment.
  773. 31:39And the reason I wanted to write this
  774. 31:41one out is because I wanted to show you
  775. 31:43two possible different scenarios here.
  776. 31:45And either one is okay. So it's not like
  777. 31:48the way you do things is 100% set in
  778. 31:50stone. You can have design decisions
  779. 31:52about the way you structure your API. So
  780. 31:54what exactly am I talking about here?
  781. 31:56Well, we could now create a comment with
  782. 31:59this post or we could create a comment
  783. 32:02with this post. Basically, we need to
  784. 32:04get the parent ID from somewhere. In
  785. 32:07this case, we're getting it from the
  786. 32:08URL.
  787. 32:10In the case of this post request, we're
  788. 32:13not providing the parent ID here, right?
  789. 32:15We're providing a parent video that the
  790. 32:18comment's going to go to, but we could
  791. 32:20still create a reply here if we wanted.
  792. 32:23It would just be passed in the body. So,
  793. 32:24it might look something like this. The
  794. 32:26video was 1 2 3. And then the body would
  795. 32:29have
  796. 32:31the content of the comment
  797. 32:37and it would have the parent ID.
  798. 32:42So both of these could work the same
  799. 32:43way. In this situation, we're passing
  800. 32:45the ID of the parent in the URL 5 67. In
  801. 32:49this one, we're passing the parent ID in
  802. 32:51the body. Either one of these are going
  803. 32:53to need some parent to grab the ID from.
  804. 32:56So the only major difference is how you
  805. 32:57want to structure the URLs and whether
  806. 32:59or not you want this to be nested under
  807. 33:01posts or not. In reality, if you're
  808. 33:03making a comment reply, doesn't matter
  809. 33:05what post it's on because that parent is
  810. 33:08unique. Basically, we have a comment 567
  811. 33:11and we are creating a reply to it. We do
  812. 33:14not care what the parent post is. We
  813. 33:16only care about the comment we're
  814. 33:18replying to. Logically, it's going to
  815. 33:20get us the same result in the database.
  816. 33:22This one just has it unnecessarily
  817. 33:24nested under a post. Let's go with one
  818. 33:26more example which would be to get a
  819. 33:28comments replies.
  820. 33:30So this might be at slash comments
  821. 33:36slash comment id
  822. 33:40slash replies.
  823. 33:42Same idea here. We don't really care
  824. 33:44about what post it's on. All we need is
  825. 33:46the ID of the comment we're replying to.
  826. 33:48So one quick comment that I wanted to
  827. 33:49add here. I would consider each one of
  828. 33:51these a different endpoint. So we have
  829. 33:54eight different endpoints here. There
  830. 33:55might be some conflicting vocabulary
  831. 33:58that you run into. So for example, we
  832. 34:00could consider all four of these
  833. 34:04to be the same endpoint with the same
  834. 34:06URL and then just have four different
  835. 34:08method options. But I don't think that
  836. 34:10makes as much sense because these in my
  837. 34:12opinion are unique interaction points of
  838. 34:14our app. So even though they're sharing
  839. 34:16a path, logically I see them as
  840. 34:18different end points. I wouldn't get too
  841. 34:20caught up in the vocabulary for this,
  842. 34:22but that's just how I tend to think
  843. 34:24about it. But what you can say is you
  844. 34:26definitely have one path with four
  845. 34:29different methods. So all of these in
  846. 34:32code
  847. 34:34could point to a single function
  848. 34:39or it could instead go to four
  849. 34:41individual functions.
  850. 34:47This is a design decision that is
  851. 34:49irrelevant from the interface of the
  852. 34:52API. The way you work with the API is
  853. 34:54exactly the same. So all of this stuff
  854. 34:56gets into how you structure the code.
  855. 34:58And I wouldn't worry too much about that
  856. 34:59right now. It's just the way you
  857. 35:02structure your code. Do you have one
  858. 35:03function and then you check what the
  859. 35:05request type is the method or do you
  860. 35:08have four different functions each one
  861. 35:09being associated with the combination of
  862. 35:12the method and the URL for unique
  863. 35:16destinations. So when we get into
  864. 35:17implementation we'll see the differences
  865. 35:19here but for now I would just focus on
  866. 35:21what the API allows us to do. So this is
  867. 35:25our full interface of how we could
  868. 35:27interact with comments. We can continue
  869. 35:30to think of different ways of how we
  870. 35:31might retrieve comments. For example, we
  871. 35:33might want all of the comments from a
  872. 35:35certain user.
  873. 35:37In that situation, it would look
  874. 35:38something like this. Get
  875. 35:42slash user
  876. 35:46slash ID. And this ID always refers to
  877. 35:50whatever it is that came before it. So,
  878. 35:51the user ID and then we could have
  879. 35:54comments.
  880. 35:56We're still working with comments, but
  881. 35:57we're basically shifting the way we're
  882. 35:58thinking about comments. Instead of
  883. 36:00associating them under a post, we're now
  884. 36:02thinking of them by user. So, we're
  885. 36:05changing the bucketing. For a simple
  886. 36:06API, you probably don't worry too much
  887. 36:08about it. You know, maybe we have just
  888. 36:10this many ways to access comments. But
  889. 36:12for a complex API, there might be a
  890. 36:14large variety of different ways to
  891. 36:16retrieve comments. And remembering the
  892. 36:19nesting and the structure for this can
  893. 36:20get complicated. I'd say starting out I
  894. 36:23prefer this structure but I want to
  895. 36:25share an alternative which is basically
  896. 36:27the comparison of
  897. 36:32nested data
  898. 36:37versus filtering
  899. 36:42and this would be filtering just a large
  900. 36:44singular collection. So let's go through
  901. 36:47examples showing the differences of
  902. 36:49these because when you're designing your
  903. 36:50API, you want to know how you're
  904. 36:52structuring the API endpoints. This is
  905. 36:54also going to get into different ways of
  906. 36:56passing data. So this is part of the
  907. 36:58path,
  908. 37:00but you can also use URL parameters,
  909. 37:03query parameters. We're going to look at
  910. 37:04those as well. So we've already talked
  911. 37:05about nested data.
  912. 37:09Basically, when we want to access some
  913. 37:13entity but relative to
  914. 37:18a collection such as the post,
  915. 37:27we can structure our URL like this. And
  916. 37:29I don't know why I didn't finish writing
  917. 37:31comments, but it's going to look
  918. 37:32something like that. Now, for filtering,
  919. 37:34we just consider having one giant bucket
  920. 37:36of all the comments. And then we provide
  921. 37:38additional information to say which of
  922. 37:40those comments we care about. So we have
  923. 37:41our giant collection of all of our
  924. 37:43comments and then we say question mark
  925. 37:47then some attribute such as the post ID
  926. 37:50and then we set that to whatever the ID
  927. 37:52is we are looking for for the post. So
  928. 37:55this concept with the question mark this
  929. 37:56is called a query parameter
  930. 38:01or you might hear URL parameter.
  931. 38:06It's slightly different than putting it
  932. 38:09in the path. So you can see here we
  933. 38:11don't use a question mark here, but
  934. 38:13functionally it can be used to achieve
  935. 38:15the same results which is changing the
  936. 38:17data that we access. So we'll talk more
  937. 38:19about the differences between using a
  938. 38:20query parameter and using the path in a
  939. 38:23moment. But for the sake of this
  940. 38:24example, it doesn't matter. All you
  941. 38:25really need to know is that we can
  942. 38:27provide some attribute to filter. So now
  943. 38:30we go from all of these comments to just
  944. 38:33a select few that we care about. And
  945. 38:35this would be based off of the post ID,
  946. 38:37whatever that value might be. In the
  947. 38:39notes, I have some additional links you
  948. 38:40can do for reading on this, but I'm just
  949. 38:42going to summarize when you might want
  950. 38:44to do each one of these. So, for
  951. 38:46relatively simple data,
  952. 38:49or another way you can think about this
  953. 38:50would be few access patterns. So, you're
  954. 38:54not going to be changing the way you're
  955. 38:56accessing comments in a bunch of
  956. 38:57different ways. For example, you might
  957. 38:59just have accessing the comments by the
  958. 39:01post and by the user.
  959. 39:04In that situation, using nested data and
  960. 39:07going with this approach is pretty
  961. 39:09clean. But if the different ways you
  962. 39:11need to access the data is vast, it can
  963. 39:14be pretty complex to create endpoints
  964. 39:16for all the different possibilities.
  965. 39:18Instead, you could just group all that
  966. 39:19together into a single
  967. 39:22dude, I am hungry. Instead, you could
  968. 39:25just group everything together into a
  969. 39:26single endpoint and allow the user to
  970. 39:28filter what they're accessing by. So if
  971. 39:30you have complex asset So if you have
  972. 39:32complex ax that's freaking tongue
  973. 39:35twister. So if you have complex access
  974. 39:37patterns you know organizing this
  975. 39:38comments by a variety of different
  976. 39:40parents. Doing this across multiple
  977. 39:42different nestings can be very
  978. 39:43complicated and ugly. So you might just
  979. 39:45put it all in one and use query
  980. 39:48parameters. This choice can actually
  981. 39:49affect your code structure as well
  982. 39:51because you might have code for posts
  983. 39:56and code for users
  984. 39:58and code for comments
  985. 40:01and you basically have to decide where
  986. 40:03you're going to store the code. So there
  987. 40:05might be some jumping around or if
  988. 40:07you're working in this other pattern
  989. 40:09where you just provide in additional
  990. 40:10filtering, you can just put everything
  991. 40:12inside of a single location for comments
  992. 40:16which can really simplify the code.
  993. 40:18surface area. You don't have a bunch of
  994. 40:19places to jump around to or have to
  995. 40:21memorize some system or architecture.
  996. 40:24So, which one do you choose? All right.
  997. 40:26My personal opinion here is I prefer
  998. 40:28this structure where we access by some
  999. 40:33parent resource. So, this is what I
  1000. 40:35prefer. If you have a certain scenario
  1001. 40:38where you're like, hey, this is just not
  1002. 40:39going to work for what I'm trying to do,
  1003. 40:41then you could consider this approach.
  1004. 40:44This approach would work well if you
  1005. 40:46need to allow for a bunch of different
  1006. 40:48filtering capabilities. Now, let's move
  1007. 40:51on to how we pass data to the backend.
  1008. 40:54So, we've talked about a few different
  1009. 40:55options here. We've talked about query
  1010. 40:57parameters.
  1011. 41:01We've talked about passing data in the
  1012. 41:03path. And we've also talked about
  1013. 41:06passing data in the request body. So,
  1014. 41:09these are the three main ways of passing
  1015. 41:11data to the server.
  1016. 41:13when do you use which? So, let's first
  1017. 41:16take a look at these two because they
  1018. 41:18have something in common. They both go
  1019. 41:21in the URL.
  1020. 41:24So, typically we'll use a path if we're
  1021. 41:26using it to identify some data that
  1022. 41:28we're referring to. So, we have the
  1023. 41:30resource, but we're not just talking
  1024. 41:32about a full collection of resources. We
  1025. 41:34want to access a specific resource. So,
  1026. 41:36very commonly, the path is going to be
  1027. 41:38an ID.
  1028. 41:40So ids usually passed
  1029. 41:47in the path
  1030. 41:50and in that situation you don't use a
  1031. 41:52question mark or an and sign you just
  1032. 41:54say something like slash123
  1033. 41:57and this is basically a unique page
  1034. 42:05or value you're referring to. So for
  1035. 42:07example, an exact comment.
  1036. 42:11So the path is used for identifying
  1037. 42:14query parameters are usually optional
  1038. 42:17and they're usually used for filtering.
  1039. 42:18So if you don't provide them, it's just
  1040. 42:20going to default to everything.
  1041. 42:23So filtering and sorting
  1042. 42:26is going to be done with a query
  1043. 42:28parameter. So if we change the ID, we
  1044. 42:30change the actual item we're looking at.
  1045. 42:33If we change the query parameter, it's
  1046. 42:36still the same path. You can think of it
  1047. 42:37as the same endpoint. It's just going to
  1048. 42:39change the filtering or sort.
  1049. 42:44So that's really important to
  1050. 42:45understand. Another thing is that with
  1051. 42:49query parameters, you can stack multiple
  1052. 42:52in a row. You can do that with the path
  1053. 42:54as well, but there's typically going to
  1054. 42:56be additional nesting. So for example,
  1055. 42:58we could have comments
  1056. 43:02then the comment ID. Then we could have
  1057. 43:06replies
  1058. 43:09and then we could have the reply ID
  1059. 43:13or whatever it may be. I'm just kind of
  1060. 43:15making this up as I go, but in this
  1061. 43:17situation, we basically work our way up
  1062. 43:19the path to get to the original
  1063. 43:24entity that we're discussing. And we're
  1064. 43:26providing multiple IDs so they have
  1065. 43:28unique names. Changing either of these
  1066. 43:30is going to change that exact comment
  1067. 43:32we're talking about. Whereas for query
  1068. 43:34parameters, we might have something like
  1069. 43:35cars question mark,
  1070. 43:40color is blue, brand is Lambo, and
  1071. 43:46sort
  1072. 43:47is ascending. And we can be more
  1073. 43:49specific. We can say price ascending.
  1074. 43:52and then the backend could still access
  1075. 43:54all of these values and you use that to
  1076. 43:56adjust the query
  1077. 43:59to the database.
  1078. 44:02You will also see the similar structure
  1079. 44:03for paged data. So pageionation,
  1080. 44:07so you might see page five or you might
  1081. 44:10see a limit on how many you're trying to
  1082. 44:12retrieve and so forth. We'll definitely
  1083. 44:14get into that. So that's query
  1084. 44:15parameters and the path. Both of these
  1085. 44:17are provided in the URL. And generally,
  1086. 44:21you do not want to do this for anything
  1087. 44:23sensitive
  1088. 44:26because think about it, if you have a
  1089. 44:28URL, that's a URL you could share with
  1090. 44:30somebody. It's something that's going to
  1091. 44:31be saved in your browser history. You
  1092. 44:33could favorite it or whatever it might
  1093. 44:35be. It's a unique link. So, if
  1094. 44:37something's private in that link, it's
  1095. 44:39very easily going to be exposed and it's
  1096. 44:41bad for security. So if there's anything
  1097. 44:43sensitive, it always goes in the body.
  1098. 44:46So for example, let's say we had a
  1099. 44:48slashregister.
  1100. 44:51You can do it the bad way,
  1101. 44:55which would be slashregister.
  1102. 45:01And then we'll provide a username
  1103. 45:04and we'll provide a pass.
  1104. 45:07and this is a unique URL that has my
  1105. 45:10username and password that I'm trying to
  1106. 45:12use for registering embedded in that
  1107. 45:14URL. This is bad.
  1108. 45:17Instead, we should just have register
  1109. 45:19and then we'll have as part of that
  1110. 45:20request a body
  1111. 45:24which will then have those attributes.
  1112. 45:26So, we'll have a username and a password
  1113. 45:30and that will be formatted in JSON. So,
  1114. 45:32it looks something like this.
  1115. 45:39So, this is the proper way to do it.
  1116. 45:41Anything sensitive goes in the body.
  1117. 45:44This is also related to if you've ever
  1118. 45:45been on a website and they have some
  1119. 45:47form and you hit submit and then maybe
  1120. 45:51something doesn't work quite right. So,
  1121. 45:52you hit the refresh button and it'll say
  1122. 45:54something like confirm form
  1123. 45:56resubmission. Basically, it's making a
  1124. 45:58request, a post request.
  1125. 46:01So forms will use post with all of the
  1126. 46:05data that you typed in as part of that
  1127. 46:07body for that request. So when it's
  1128. 46:09asking you if you want to resubmit that
  1129. 46:11form, it's basically saying, "Hey, do
  1130. 46:12you want me to send another post request
  1131. 46:14to the back end? We already did it
  1132. 46:16once." But yeah, translation, what does
  1133. 46:18that mean for you? It means anytime we
  1134. 46:20have an HTML form, it's going to use the
  1135. 46:23post
  1136. 46:25request type for that submission. and
  1137. 46:27that means any of that data does not get
  1138. 46:29added into the URL. However, if you're
  1139. 46:31not doing anything sensitive and you
  1140. 46:33just want to give the user the ability
  1141. 46:34to sort and filter, you can make those
  1142. 46:36drop downs and make the request at the
  1143. 46:38back end with that in the URL. So, with
  1144. 46:40this in mind, let's look at what a full
  1145. 46:42request might look like. You might have
  1146. 46:44post
  1147. 46:47SL API/ users. So, this would be
  1148. 46:49creating a new user. You could also have
  1149. 46:51it be SLregister. You'll have any other
  1150. 46:53headers. So you'll often see content
  1151. 46:56type and this is how you basically say
  1152. 46:59the notation being used for the request
  1153. 47:03and this will be
  1154. 47:05application slashjson.
  1155. 47:08Then we'll skip down here. We'll open
  1156. 47:11body
  1157. 47:14and then any attributes we want to send
  1158. 47:15to the back end. So here is some example
  1159. 47:19data all within JSON. This is a pretty
  1160. 47:22common structure you're going to see.
  1161. 47:24So, for example, if you're working with
  1162. 47:25API testing tools, for example, curl or
  1163. 47:28some of these other tools out there to
  1164. 47:29make requests to APIs and you're
  1165. 47:31formatting the structure of the request,
  1166. 47:33it might look something like this. So,
  1167. 47:35this is an example of a header content
  1168. 47:37type, really common one to specify JSON,
  1169. 47:39but there are other headers you're going
  1170. 47:41to become familiar with as well. And
  1171. 47:43this is data that's passed with the
  1172. 47:45request, but it's different than the
  1173. 47:46body. You can think of headers as
  1174. 47:48metadata, which is data about our data
  1175. 47:51describing how to interpret the data,
  1176. 47:53for example. And we'll use headers for
  1177. 47:55all kinds of different things. Now, last
  1178. 47:57thing I'm going to touch on briefly
  1179. 47:59because we're going to dedicate a lot of
  1180. 48:00the next lesson's material on this that
  1181. 48:03is status codes
  1182. 48:09or response codes.
  1183. 48:12So just like there are standard HTTP
  1184. 48:14methods, you know, get, post, put, all
  1185. 48:16that stuff, there are status codes which
  1186. 48:19are included with the response from the
  1187. 48:21server. So we just looked at how to make
  1188. 48:22a request, but the backend might give
  1189. 48:24back a status code. For example, 201.
  1190. 48:28This is just one example of a status
  1191. 48:30code. And every single one of these
  1192. 48:32codes has some implicit meaning. Now you
  1193. 48:34as the API developer you can send back
  1194. 48:37whatever status codes you want but
  1195. 48:39generally you'll follow conventions in a
  1196. 48:41similar way you do with HTTP methods. So
  1197. 48:442011 this will have the text associated
  1198. 48:46with it which is created
  1199. 48:49and when a client sees this it can
  1200. 48:52interpret that message to mean hey we
  1201. 48:54likely created a new resource.
  1202. 48:59So this is a common response for a post
  1203. 49:02request where we're creating a new value
  1204. 49:05in the database. So there are a bunch of
  1205. 49:07different codes in the 100 range to the
  1206. 49:09500 range. Each one meaning something
  1207. 49:12unique, but there are different
  1208. 49:13categories. The big ones you should
  1209. 49:15concern yourself with are the 200 level
  1210. 49:18which are all kind of like okay things
  1211. 49:21are working.
  1212. 49:24300s are redirects,
  1213. 49:30400's are client errors,
  1214. 49:36and then 500 are server errors.
  1215. 49:40So, in the next lesson, we're going to
  1216. 49:42look at more of these status codes and
  1217. 49:44how you should interpret those from the
  1218. 49:46client. What do you do if you get a
  1219. 49:48certain status code? as well as as the
  1220. 49:51API developer, how to know which status
  1221. 49:53codes to use in what scenarios. So
  1222. 49:56that's what we're going to get to in the
  1223. 49:57next lesson. As well as once you do all
  1224. 49:59of this,
  1225. 50:03we now have a fairly complex
  1226. 50:07interface to work with our API.
  1227. 50:11We need some way to describe this to
  1228. 50:14other users.
  1229. 50:16So this gets into the world of API
  1230. 50:18documentation and specs.
  1231. 50:22Since we're following some standards,
  1232. 50:24maybe people can get an idea of how our
  1233. 50:26API works without us even having to say
  1234. 50:29anything. So, this gets into the world
  1235. 50:30of Open API and various other things.
  1236. 50:33So, we're going to talk about all of
  1237. 50:34that in the next lesson. So, just so you
  1238. 50:36have an idea of some of the things I
  1239. 50:37have for the next couple of lessons, I'm
  1240. 50:39really interested in talking about those
  1241. 50:41status codes, API documentation and
  1242. 50:43specs, proper API architecture for
  1243. 50:46scalability. We're going to look at
  1244. 50:48authentication at a high level, how it
  1245. 50:50interacts with APIs, things like API
  1246. 50:52keys and JWTs. We will also look at
  1247. 50:54pageionation and how we can transfer a
  1248. 50:57lot of data to the end user in sections
  1249. 51:00instead of just giving everything at
  1250. 51:02once. That and so much more. So, I'm
  1251. 51:04super super excited if you made it this
  1252. 51:06far in the lesson. Really appreciate it.
  1253. 51:07Hopefully, it was really helpful. Again,
  1254. 51:09just wanted to give you a reminder to
  1255. 51:10check the playlist. The playlist is
  1256. 51:13where you're going to find all of the
  1257. 51:15good stuff and you can just watch it
  1258. 51:16sequentially. Go through this material
  1259. 51:18one lesson at a time and I promise I'll
  1260. 51:20help you become a much better software
  1261. 51:21developer. So, super excited. I know
  1262. 51:24I've said that like five times, but it's
  1263. 51:26just really awesome and I'm really happy
  1264. 51:27to be doing this. So, thank you so much
  1265. 51:29for watching. Check out the playlist.
  1266. 51:30Check out the notes for this lesson and
  1267. 51:32the upcoming lessons. I'll have a link
  1268. 51:33down for that below. Check out the
  1269. 51:34fundamentals course and my other courses
  1270. 51:36available if you're interested. And with
  1271. 51:38that, I will see you in the next lesson.
  1272. 51:40Thank you so much. Peace out.

About this transcript

This page contains the full transcript of API Design and Architecture - Backend Engineering Intro (1 Hour) by Caleb Curry, generated from the public captions YouTube serves with the video. The transcript has 8,377 words across 1,272 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.