YouTube2Text

API Status Codes and OpenAPI Documentation - Backend Engineering — Transcript

by Caleb Curry · 4,315 words · 653 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Hey, what's going on everybody? It's
  2. 0:01Caleb. In this lesson, we're going to
  3. 0:02talk about the HTTP status codes that
  4. 0:05you need to know when you're building an
  5. 0:07API. Now, before we get started, I will
  6. 0:09tell you that you can get the playlist
  7. 0:11link down below so you can watch all of
  8. 0:13my back-end engineering videos. That'll
  9. 0:15get you started with an intro to APIs
  10. 0:17lesson. And the second thing you need to
  11. 0:19know is that I have the notes for this
  12. 0:20lesson and all the other lessons. You
  13. 0:22can get that as well in the link below.
  14. 0:24So that'd be great if you want to follow
  15. 0:26along with some code examples as well as
  16. 0:28a ton of additional resources and links.
  17. 0:30So would really recommend that to get
  18. 0:32you the most success possible here. So
  19. 0:34we've already talked about APIs. It's
  20. 0:36basically a way to make a request to a
  21. 0:39backend and then the backend will give
  22. 0:41back a response
  23. 0:44and this will include a code
  24. 0:48such as 200 and these will also have
  25. 0:51some message associated with it such as
  26. 0:54okay. So these codes they have some
  27. 0:57implied meaning but you as the backend
  28. 1:00developer usually decide what code to
  29. 1:03send to the client. So let's say the
  30. 1:05client makes a request for some data
  31. 1:11that hits the server. The server then
  32. 1:13checks the database
  33. 1:16and the database does not find the data.
  34. 1:19Whatever they're looking for is not
  35. 1:21there. So the server can then respond to
  36. 1:23the client
  37. 1:28with a 404
  38. 1:30not found.
  39. 1:33But you can control that. You can return
  40. 1:35whatever you want. There are just
  41. 1:37conventions and approaches that if you
  42. 1:39follow these approaches, you will create
  43. 1:41an API that people already know how to
  44. 1:43use. Additionally, you can follow a spec
  45. 1:47or a specification and this will allow
  46. 1:50for very easy consumption of your API.
  47. 1:53So the most common example of this would
  48. 1:55be an open API spec.
  49. 1:59And basically, if you want to use one of
  50. 2:01these specs, you just describe the
  51. 2:04behavior of your API, what data is
  52. 2:06expected, what kind of responses might
  53. 2:08be given back, and you put all of that
  54. 2:11into a spec file, which can then be read
  55. 2:13by other software. So, we'll definitely
  56. 2:15get into this idea in more detail, but
  57. 2:17this is a concept video, so we're not
  58. 2:20going to build an open API compatible
  59. 2:23API in this lesson, but we'll probably
  60. 2:25do that in upcoming lessons. So, again,
  61. 2:26check out the playlist link down below.
  62. 2:28So, if you're watching this video, you
  63. 2:29may already understand the basics of
  64. 2:31APIs, but you want to know the proper
  65. 2:33way to build an API. Maybe you can build
  66. 2:35an API, but you want to know the proper
  67. 2:38conventions, the proper structures, the
  68. 2:40way you return data, what status codes
  69. 2:42to use. That's what we're going to cover
  70. 2:43in this lesson. So, before we get into
  71. 2:45the status codes, we're going to talk
  72. 2:47about the body structure. So, with a
  73. 2:50request and a response, you can include
  74. 2:51a body. And I want to talk about the
  75. 2:53conventions for returning data from the
  76. 2:55server. We can do one of three things.
  77. 2:59We can return an array of data.
  78. 3:03We can return an object
  79. 3:05or we can return the data as an
  80. 3:08attribute
  81. 3:12of another object. So we would be
  82. 3:14returning data as a nested object.
  83. 3:20So these are three different approaches
  84. 3:22and not all of these are correct. So,
  85. 3:25while it's technically possible to just
  86. 3:27return an array directly from an API,
  87. 3:30it's not considered best practice. So,
  88. 3:32for example, let's say we had users on
  89. 3:35our app and they were able to configure
  90. 3:37their profile settings and one of the
  91. 3:40things on here was notification
  92. 3:42settings.
  93. 3:45And let's say they could get
  94. 3:47notifications for marketing information.
  95. 3:49They could get notifications from any
  96. 3:51replies to their comments. and they
  97. 3:53could get notifications for security
  98. 3:55issues with their account. So these
  99. 3:58might be in an array
  100. 4:00where we have marketing
  101. 4:04replies and security.
  102. 4:11So if we wanted to get the person's
  103. 4:13notification settings or the same idea
  104. 4:15if we wanted to update the user's
  105. 4:17notification settings, the method and
  106. 4:20the path would look something like this.
  107. 4:22We could use a get for retrieving this
  108. 4:24information
  109. 4:26or we could use a patch for updating
  110. 4:29this information.
  111. 4:32Then we would have slash users
  112. 4:35slash the ID of the user slash
  113. 4:39notifications
  114. 4:41or you could have a more general slash
  115. 4:43settings. But let's just say we're
  116. 4:45working with notifications directly and
  117. 4:47we want to get this data for a
  118. 4:49particular user. So let's say user 1 2
  119. 4:513. What does the response body look
  120. 4:53like? Well, it's considered bad practice
  121. 4:55to just return an array. So, the proper
  122. 4:57way to do this would actually be to
  123. 4:59encapsulate that array in an attribute
  124. 5:00of an object. So, that might look like
  125. 5:03this. We have a curly brace and then an
  126. 5:05attribute
  127. 5:07notifications
  128. 5:11and then the value of that attribute is
  129. 5:13the array and then we can close the
  130. 5:15curly brace. Same idea when we send data
  131. 5:18to the server. or if we were to use a
  132. 5:20patch, we would nest that array in some
  133. 5:24attribute. I think that's considered
  134. 5:26best practice. So, you always want to be
  135. 5:28working with the first level being an
  136. 5:30object.
  137. 5:33Inside of that object, you can do pretty
  138. 5:35much whatever you want. Let's go through
  139. 5:36another example. Let's say you wanted to
  140. 5:38get all of the users.
  141. 5:42Well, users is going to naturally give
  142. 5:44us an array. And this would be an array
  143. 5:47of objects. So within the square
  144. 5:50brackets you would have multiple
  145. 5:52objects. So it would look something like
  146. 5:54this where each one of these is a user.
  147. 5:57However, same idea here. I don't think
  148. 5:59it's ideal to return an array back to
  149. 6:02the client. So instead we would nest
  150. 6:04this in a bigger object. So it looks
  151. 6:07something like this.
  152. 6:10users
  153. 6:13square bracket and then that data.
  154. 6:20So this is the proper response. Now a
  155. 6:22scenario where this is a little less
  156. 6:24clear is if we're working with an
  157. 6:25endpoint that doesn't directly give us
  158. 6:27an array. What if we want to say
  159. 6:33get
  160. 6:36get users and pass in a specific user
  161. 6:39say ID 3 2 1. Well, this is going to get
  162. 6:42us a single user. So, the response type
  163. 6:44is an object. We can give a a quick
  164. 6:47example here such as name
  165. 6:51being Caleb.
  166. 6:55So here's where you have basically one
  167. 6:57of two options. We can return an object
  168. 7:00or we can return data as a nested
  169. 7:02object. So you could basically just
  170. 7:04return this
  171. 7:08and that would work fine.
  172. 7:11That's pretty common, but it's probably
  173. 7:13not as ideal as still returning the
  174. 7:16object as a nested attribute in a larger
  175. 7:20object. Just like we did with the array,
  176. 7:22it's just now a single user instead of
  177. 7:24multiple users. So we would have user
  178. 7:27and the value for this would then be
  179. 7:30that object.
  180. 7:32So it looks something like this.
  181. 7:36So that closes this inner object and
  182. 7:38then this outer curly brace closes the
  183. 7:41outer object. So you can see that this
  184. 7:43structure and this structure is
  185. 7:45consistent. We basically have an
  186. 7:47attribute describing what the data is
  187. 7:49and then we have the data where that
  188. 7:51data is either an array or an object.
  189. 7:53This is pretty much what I would always
  190. 7:54do. So just nest it in some attribute
  191. 7:57and you can describe what the data is
  192. 7:59such as saying users or user. So the
  193. 8:01conclusion from this is even if you're
  194. 8:02working with an endpoint that gives us
  195. 8:04just a single object, we still nest it
  196. 8:06inside of a larger object. And there's
  197. 8:09one other major benefit to this other
  198. 8:11than just being consistent and that is
  199. 8:13it gives us the ability to add in
  200. 8:15additional information into this outer
  201. 8:18object without affecting the inner
  202. 8:22object. So you can see we have this
  203. 8:23inner object here and I guess we'll
  204. 8:26include the attribute name.
  205. 8:30But for this outer object, we can put in
  206. 8:33extra information to describe the
  207. 8:35request, pass in status information,
  208. 8:38continuation tokens or whatever it may
  209. 8:40be. It basically gives us room to
  210. 8:42provide additional information to the
  211. 8:44client without impacting the actual data
  212. 8:47they care about. So here's what that may
  213. 8:48look like. We can have a large outer
  214. 8:51object. The thing we're giving back to
  215. 8:53the client is a user.
  216. 8:56This contains an object with some
  217. 8:58attributes such as name
  218. 9:02that has a value Caleb.
  219. 9:05And then we'll close that object. You
  220. 9:06can additionally put in different
  221. 9:08attributes here and close the object.
  222. 9:10We're just going to have one attribute
  223. 9:11now for simplicity. But this outer
  224. 9:13object, we're going to keep that open.
  225. 9:14And we're going to then close it down
  226. 9:15here, which gives us room to add in
  227. 9:17additional attributes.
  228. 9:19So, we could have a meta attribute for
  229. 9:22any kind of metadata about the request.
  230. 9:25I'll just draw that as an empty object.
  231. 9:27We could have an API version
  232. 9:30and that could just be a number.
  233. 9:32Sometimes the response is embedded in
  234. 9:35the body even though it's a little bit
  235. 9:36redundant with the HTTP status code in
  236. 9:39the actual response, but that is
  237. 9:42possible to see. So we'll say response
  238. 9:45200 or if we're working with a list of
  239. 9:49users
  240. 9:51maybe we have to do pageionation and
  241. 9:54that information could be included here
  242. 9:55as well.
  243. 10:00So we may have a continuation token
  244. 10:04and the client can then access this
  245. 10:07attribute to know how to make another
  246. 10:10request.
  247. 10:14So, I haven't really talked about paging
  248. 10:15yet. That's not the important part here.
  249. 10:17The important part is that we can add in
  250. 10:20a bunch of additional information if we
  251. 10:22need because of the way we structured
  252. 10:23the response. So, this is the structure
  253. 10:26I'm going to follow. A very easy way to
  254. 10:28structure this in the code would be to
  255. 10:30create some variables such as data. And
  256. 10:31here you would make a database call. I'm
  257. 10:33just making this up, but it might be
  258. 10:35something like users.get.
  259. 10:39And then when you return a response,
  260. 10:43you can just take this variable,
  261. 10:45regardless of what it is, whether it's
  262. 10:46an object or an array, and provide that
  263. 10:49inside a dictionary
  264. 10:51like so.
  265. 10:55So you'll see this structure quite a bit
  266. 10:57where in our code we're working with an
  267. 10:58array or a single object, but then when
  268. 11:00we actually provide the response, we
  269. 11:02just embed it in a dictionary with
  270. 11:04another attribute. But again, we could
  271. 11:06then add anything inside of here besides
  272. 11:09the users attribute. We could add any of
  273. 11:12these things. So hopefully that's
  274. 11:14helpful in understanding the proper
  275. 11:15structure for the response. Cool. So we
  276. 11:17got that out of the way. Now we can take
  277. 11:19a closer look at status codes. So off
  278. 11:22the top of my head, the ones you should
  279. 11:23know immediately are 200, 2011,
  280. 11:27204,
  281. 11:29301, and 302,
  282. 11:32400, 403,
  283. 11:36404, and 500. So if you know all of
  284. 11:39these, you'll be pretty good. And each
  285. 11:41one of these will also have a small
  286. 11:42description attached to it. So for
  287. 11:44example, 404
  288. 11:47not found.
  289. 11:49I'm not going to necessarily write that
  290. 11:50out every single time or say it out loud
  291. 11:52every single time. So, just know that
  292. 11:54each one of these will have some message
  293. 11:56with it. So, let's go through each one
  294. 11:57of these. 200 is okay. That means
  295. 12:00everything worked as expected. You'll
  296. 12:02likely get some data back. 2011 created
  297. 12:05usually means you're creating some new
  298. 12:07resource and it was successful. 204, no
  299. 12:10content. This basically means it was a
  300. 12:12success, but the server has nothing to
  301. 12:14give back to you. 301 and 302, these are
  302. 12:16two types of redirects. a permanent
  303. 12:18redirect and a temporary redirect. So
  304. 12:20this is 301 move permanently and then
  305. 12:22302 found 400 bad request. This implies
  306. 12:26an issue with what you're sending from
  307. 12:28the client to the server. So maybe
  308. 12:30that's an issue with the way you
  309. 12:32structured the body and you need to fix
  310. 12:34that. 404 not found means the path
  311. 12:36you're giving doesn't exist. And then
  312. 12:38lastly, 500 internal server error. This
  313. 12:41means something went wrong on the server
  314. 12:43side. So this is a client error.
  315. 12:45Something's wrong with the request. this
  316. 12:47is a server error. Maybe there was an
  317. 12:48error with the database. So your job as
  318. 12:51the person building the API is to use
  319. 12:53the proper status codes to describe
  320. 12:55what's happening. To get to the solution
  321. 12:57to this rather quickly, there's
  322. 12:59basically five different request
  323. 13:01categories and the different responses
  324. 13:03for them. So we have
  325. 13:07a get for many elements,
  326. 13:11a get for a single element, a post,
  327. 13:17a put or patch,
  328. 13:20and a delete. Now, there are more method
  329. 13:23types. These are the main ones you
  330. 13:24should be familiar with starting out.
  331. 13:26And if you got all this down, the
  332. 13:27concepts are there, and you can pick up
  333. 13:28all the others quite easily. So when
  334. 13:30you're getting many that would be
  335. 13:31something like slash users and things
  336. 13:33work you will either get some data or
  337. 13:36you will get an empty array. So this is
  338. 13:38going to give 200 and return an array
  339. 13:42and keeping in mind that'll be an
  340. 13:43attribute inside of the response object.
  341. 13:46But it'll either be an empty array or an
  342. 13:49array with data. You're not just going
  343. 13:50to give back nothing. Now if you're
  344. 13:52getting a single resource that would be
  345. 13:54something like users
  346. 13:57ID 1 2 3. This is going to give an
  347. 14:00object. So you'll get 200 and an object.
  348. 14:04However, this could also give a 404 if
  349. 14:07that object is not found. So that is an
  350. 14:10important thing to understand here. If
  351. 14:12you're getting many and nothing is
  352. 14:14retrieved, for example, you want to get
  353. 14:17all of the comments on a video, but that
  354. 14:19video has zero comments, you're going to
  355. 14:21get an empty array. However, if you're
  356. 14:23getting a single element and the element
  357. 14:25does not exist, you're going to get a
  358. 14:27404. you're not going to return an empty
  359. 14:29object. So, we could potentially get
  360. 14:31back a 404 if we're getting a single
  361. 14:33element. It'd be like if you put an ID
  362. 14:34here that wasn't in the database. Now,
  363. 14:36for post, you will usually see 200 or
  364. 14:40201.
  365. 14:42So, usually 201 is used for creating new
  366. 14:44data. And then often this will return
  367. 14:48the ID of the newly created thing or the
  368. 14:51new object entirely.
  369. 14:53This can also give back a 400 if you
  370. 14:56give bad data to the request. So if the
  371. 14:59data you're trying to create is invalid,
  372. 15:02then you can get a 400. Or if that
  373. 15:04insert is not working properly, you
  374. 15:06might get a 500 for the server error.
  375. 15:09Now put or patch, you will often get a
  376. 15:11200 or a 204,
  377. 15:14which basically says it works, but the
  378. 15:16server doesn't give back any data. If
  379. 15:18it's a 200, you will often get the
  380. 15:20updated object back.
  381. 15:23possible issues. We can now get a 404.
  382. 15:26If the resource we're trying to update
  383. 15:28doesn't exist. So, for example, if we
  384. 15:30were trying to update users
  385. 15:331223, but 123 didn't exist, we could get
  386. 15:35a 404, but we can also get a 400 for bad
  387. 15:39data or a 500 for an issue on the
  388. 15:41server. And then lastly, delete. I'll
  389. 15:43usually do a 204, but you may also see a
  390. 15:46200 with the response being the number
  391. 15:48of affected rows or some other
  392. 15:51variations. This isn't necessarily the
  393. 15:53only way to do it. This here is not the
  394. 15:55spec. The spec is adhering to a proper
  395. 15:58HTTP protocol, but you can choose what
  396. 16:01can possibly happen, and this is what's
  397. 16:03going to show up in your documentation.
  398. 16:05So, I'm just showing some common things
  399. 16:06you'll likely see. So, if you're like,
  400. 16:08"Oh, I don't know what status code to
  401. 16:10use for a post or a delete," here's your
  402. 16:12answer. Now, a delete could also give a
  403. 16:15404 if we're trying to delete something
  404. 16:17that doesn't exist or a 500. It's
  405. 16:20probably not going to give a 400 because
  406. 16:22that would imply bad data from the user,
  407. 16:24but you're not really providing data to
  408. 16:26the back end for a delete beyond just
  409. 16:27the ID of the thing you want to delete.
  410. 16:30So, usually you're going to get a 404 or
  411. 16:32a 500. And then we're not really
  412. 16:34worrying about 301's and 302s, but those
  413. 16:37are good to know about. And then 403
  414. 16:39here, we didn't talk about this because
  415. 16:42we're not really concerned about
  416. 16:44authorization or authentication here. So
  417. 16:46we're going to talk about that, but you
  418. 16:47can think of this separately from our
  419. 16:49core functionality. So the client can
  420. 16:51use these status codes to adjust its
  421. 16:53behavior. So for example, if we make a
  422. 16:56request to post slash comments,
  423. 17:01what were the potential returns for
  424. 17:03this?
  425. 17:04If it was a success, we'll get a 200 or
  426. 17:07a 2011. If there's something wrong with
  427. 17:09our data, we could get a 400.
  428. 17:12If there's something wrong with the
  429. 17:13server with the insert or something
  430. 17:16along those lines, we could get a 500.
  431. 17:20Additionally, to post a comment, you
  432. 17:22might need to be logged in probably. So,
  433. 17:24can have another option here with a 401.
  434. 17:28So, we basically have four possible
  435. 17:30paths we have to consider on the client.
  436. 17:33If it's a 200, we could add the comment
  437. 17:35to the feed so it visually looks like
  438. 17:38our comment was posted. If it's a 400,
  439. 17:40we might say, "Yo, try again."
  440. 17:44And maybe we could figure out a little
  441. 17:46bit more detail why it's a 400. So if
  442. 17:49you have some backend validation
  443. 17:50library, it will usually give some more
  444. 17:53specific error that you can send back in
  445. 17:56the response. So it might say something
  446. 17:58like, "Oh, the body is required or the
  447. 18:01message is too long or whatever it might
  448. 18:02be." So you can show that error.
  449. 18:08So, show error and then prompt the user
  450. 18:11to try again. You don't just try again
  451. 18:14without any changes because that client
  452. 18:16error isn't going to have been fixed
  453. 18:18automatically.
  454. 18:20That might be different for a server
  455. 18:21error. Maybe something went wrong and we
  456. 18:22just want to retry. But basically, with
  457. 18:24a server error, we would just say a
  458. 18:27general error message.
  459. 18:30We usually don't want to give too much
  460. 18:31information about issues from the
  461. 18:33server. So, we keep it pretty general to
  462. 18:35the client. If it's a 401, we can
  463. 18:38redirect
  464. 18:40to the login page. So, you can see how
  465. 18:42these status codes can be very handy
  466. 18:44because it allows us to build a client
  467. 18:46that can respond smartly to whatever
  468. 18:48happens from the server. Next up, I want
  469. 18:50to talk about a concept called
  470. 18:51middleware. And this can be very handy
  471. 18:53when we are building out responses. And
  472. 18:55often middleware steps can return
  473. 18:58different status codes. So far, we have
  474. 19:00been taking requests and coming up with
  475. 19:04different responses. But this processing
  476. 19:07is just one piece in a much larger
  477. 19:10request cycle. So I'm just going to draw
  478. 19:12this as a box. But what it might really
  479. 19:14look like is you receive a request from
  480. 19:17the client on the server
  481. 19:20and then it goes through some steps. So
  482. 19:23for example, it might go through an off
  483. 19:26middleware which is a really common
  484. 19:28structure.
  485. 19:30And then before we give the response
  486. 19:33back to the end user, we might have some
  487. 19:36formatting or some internationalization.
  488. 19:40So these things effect on the after
  489. 19:44processing of the request and then we
  490. 19:46can send it to the client.
  491. 19:49So basically things can happen before
  492. 19:52the request and after the request that
  493. 19:55can modify the request or modify the
  494. 19:57response. So earlier when we mentioned
  495. 19:59the most common methods and the common
  496. 20:01status codes I was kind of like hey you
  497. 20:03can worry about off separately that's
  498. 20:06because you could have an off middleware
  499. 20:08and this verifies the user so it checks
  500. 20:12for authentication authorization
  501. 20:15so very similar ideas slightly different
  502. 20:18authentication is basically saying hey I
  503. 20:20am who I say I am I can prove that to
  504. 20:22you here's my username and password
  505. 20:25whereas authorization deals with do I
  506. 20:28have access to what I'm trying to
  507. 20:29access. I might be able to log in, but
  508. 20:32do I have the permissions to do whatever
  509. 20:34I'm trying to do? So, two slightly
  510. 20:37different ideas. And it's even super
  511. 20:39confusing because the 401 status code
  512. 20:42generally means the person needs to log
  513. 20:44in. They're unauthenticated,
  514. 20:47but the message with it is unauthorized.
  515. 20:54So, don't let that trick you. And then
  516. 20:55there's a 403 forbidden
  517. 21:02which is really the unauthorized. So
  518. 21:05this is
  519. 21:07unauthenticated.
  520. 21:11Can't even fit that in there. And then
  521. 21:12this is unauthorized.
  522. 21:16So you can almost think of these as
  523. 21:17backwards.
  524. 21:19So we'll get a 401 when the user needs
  525. 21:21to log in and then a 403 if they're
  526. 21:23trying to do something that they're not
  527. 21:24supposed to be doing. So all of these
  528. 21:26capabilities can be encapsulated in a
  529. 21:29separate function as part of the
  530. 21:31middleware pipeline.
  531. 21:34So each one of these steps would be a
  532. 21:35step in that pipeline. And the request
  533. 21:37goes through this linearly, one at a
  534. 21:39time, with each step potentially
  535. 21:41modifying or adding to or changing the
  536. 21:45request that passes through this
  537. 21:47pipeline until it ultimately gets back
  538. 21:48to the client.
  539. 21:50So this doesn't change the end output
  540. 21:53for the user. It just changes the way we
  541. 21:54structure our application and think
  542. 21:56about requests. So this is more a code
  543. 21:59organization and scalability of our code
  544. 22:02idea. The end user doesn't see or know
  545. 22:04anything about this. We may also have
  546. 22:07things like validation
  547. 22:12and this could potentially return 400s.
  548. 22:16So then we wouldn't even have to worry
  549. 22:17about 400s in the request in the section
  550. 22:20where we're processing the request
  551. 22:21because if they make it through the
  552. 22:23validation and they didn't get a 400,
  553. 22:26then we know the content
  554. 22:30is valid and then we can process it.
  555. 22:34So this allows our core processing logic
  556. 22:37to be very thin
  557. 22:40and single focused basically. So it's a
  558. 22:42very nice way to organize and structure
  559. 22:44our code and then we don't have to
  560. 22:46repeat logic in every single function.
  561. 22:49Very very important. Last thing is API
  562. 22:52documentation
  563. 22:53and specs.
  564. 22:56So it's often the case whatever library
  565. 22:58or language you're using
  566. 23:03will have some way to work with
  567. 23:08or document
  568. 23:14your API and this might be some specific
  569. 23:18internal tool for that library or it
  570. 23:20might use external things like creating
  571. 23:23an open API spec file. So your library
  572. 23:26might be able to generate a YML orJSON
  573. 23:33file
  574. 23:35and this can then be read by other tools
  575. 23:39to generate docs
  576. 23:43and interfaces to work with the API.
  577. 23:47This is huge. Anytime you can generate
  578. 23:49stuff, you should probably do it. So an
  579. 23:51example of an other tool here would be
  580. 23:53Swagger.
  581. 23:56And this is closely associated with open
  582. 23:58API, but it's not the same thing. Think
  583. 24:00of Swagger as the tool. Open API is the
  584. 24:04actual spec, but Swagger can read Open
  585. 24:07API documents and give us a very easy to
  586. 24:10use UI to interact with that API. So
  587. 24:13then if you're working in a team or you
  588. 24:15need to share this API with other
  589. 24:16people, you don't have to tell them what
  590. 24:18every single possible thing is. they can
  591. 24:20just look at the UI and see the possible
  592. 24:22inputs and potential errors or output
  593. 24:24concerns they need to consider. So this
  594. 24:26makes building the actual interaction
  595. 24:29between the back end
  596. 24:32and the front end
  597. 24:35a thousand times easier.
  598. 24:38So check with whatever library you're
  599. 24:40working with if they have a way to
  600. 24:41generate the open API spec or there's
  601. 24:44likely another library for the language
  602. 24:46that you can download to do that. If
  603. 24:47not, you can create these files yourself
  604. 24:49manually. It's not like impossible. So,
  605. 24:51you can do that as well if you're
  606. 24:53working with a perhaps newer language
  607. 24:55that doesn't have as many good libraries
  608. 24:57out there. There are also other options
  609. 24:59for documentation. For example, there's
  610. 25:01Postman.
  611. 25:04And this is generally considered a tool
  612. 25:06to interact with an API, to test it, to
  613. 25:08build an API. You can think of it as an
  614. 25:10alternative to a web browser, but with
  615. 25:12stronger support for the different
  616. 25:13methods and the different variations
  617. 25:15you'll need for testing APIs. But you
  618. 25:17have the ability in Postman to create
  619. 25:19collections
  620. 25:21and collections can act as a
  621. 25:24documentation for your API basically
  622. 25:27showing what endpoints, what they
  623. 25:29expect, and so forth. And Postman has
  624. 25:31ways to generate docs
  625. 25:37from these collections. So, in the
  626. 25:39notes, I'll leave additional information
  627. 25:40if this is something you're interested
  628. 25:42in. Last couple of things I want to
  629. 25:43mention just as a bonus here is you can
  630. 25:46also utilize AI, which should be able to
  631. 25:50document APIs on the fly.
  632. 25:54So, that's another alternative is to
  633. 25:56actually document when you need the API
  634. 25:59using AI. Or another thing I want to
  635. 26:01mention is you can go through the effort
  636. 26:02to build a docs website such as
  637. 26:05docysaurus or some other markdown
  638. 26:07renderer.
  639. 26:10This is pretty important or more common
  640. 26:12for public APIs.
  641. 26:16So that's something you might want to
  642. 26:17look into as well. That's all I have in
  643. 26:18this lesson. Hopefully it was a good
  644. 26:20introduction to the different codes you
  645. 26:21might run into. There are a ton, but the
  646. 26:24ones we covered are the most important
  647. 26:26to get started. And as we build out APIs
  648. 26:29here soon, we will see these again.
  649. 26:30Thank you so much for watching and stay
  650. 26:32tuned for the upcoming lessons. Be sure
  651. 26:34to check out the playlist link. That's
  652. 26:35where I'll put everything. And I'll see
  653. 26:37you in the next one. Peace out.

About this transcript

This page contains the full transcript of API Status Codes and OpenAPI Documentation - Backend Engineering by Caleb Curry, generated from the public captions YouTube serves with the video. The transcript has 4,315 words across 653 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.