Placeholder Image

Subtitles section Play video

  • today we're gonna build your very first rest a p I as quickly as possible.

  • Let's get started now.

  • Now, in order to create this rest a pia we're going to be using know Js Express and Mongo D B.

  • In order to get started with that, we first need to run N p m in it.

  • So we just typing and PM in it.

  • And we just want to enter a bunch of times in order to get all the default values.

  • And as soon as we do that, it's going to create a package that Jason for us next, we wanted to stall the dependencies that we're gonna use.

  • So our dependencies, we could just hide N p m I.

  • And our first dependency is going to be expressed and then the next dependency that we're going to be having his mongoose, which is going to allow us to interact with Mongo to be easily express, is really useful for when we want to create an application using no Jess because it's just much easier to create a Web application using express than standard Js.

  • Next, we want to use MPM to install her development tendencies.

  • So we could say in P M I.

  • And we just want to say Dash Dash, Save Dev, which is going to make these be development dependencies that do not get installed in production.

  • And we want to use Di e n v and we also want to use Node Mon Now Dottie envy is going to allow us to polling environment variables from a dotty and V file and knowed Monte will allow us to refresh our server every time we make changes.

  • But I have to manually ended and restart it.

  • Now that we have all those installed, let's remove this test script and create our own script called Dev Start which will allow us to start our server using knowed monte.

  • And we just want to type in node mon, followed by the name of our script which would appoint a call server dot Js.

  • We can say that and actually create that new file called server dot Js.

  • And here we go.

  • This is where we're going to put all of our different server code and before we get started any further, we want to create that Dottie Envy folder while right here.

  • And this is going to have our environment variables.

  • We also want to create a dot get ignore, since we're going to be storing this on, get using, get hub orbit, bucket or whatever you want to use.

  • And we want to ignore our Dottie Envy file, since I was going to have sensitive information on.

  • We also want to ignore our Node Modules folder because this could be installed and created by just running NPM install whenever you download the code from get home or wherever it's stored.

  • Now, with that out of the way, let's greater actual server and the first thing we want to do is we want to require express.

  • So what does create a variable, which is called Require Express just like that?

  • And that's going to pulling the express library.

  • Next, we want to create a variable called App on.

  • We just want to run on express function just like this, and that's going to create an at variable, which we can use to configure our server Next.

  • We could just say ap dot Listen, tell what the port we want.

  • It was none in our case, 3000 and we're just going to pass it a function here and this gets run whenever our server get started.

  • So we're just gonna log out that our server was started, so we'll say council about log.

  • And we just want to say that this server has started.

  • Now, if we say that we run that method that we created earlier, which is NPM Run, Davis, start it.

  • Enter.

  • This is going to start up our server using note, Mon.

  • As you can see, it says server started down here and we could go to this app local host 3000 and our server's gonna be running there.

  • But right now it doesn't do anything.

  • So let's make our application actually do something next.

  • We want to configure Mon Goose to connect our mongo DP database.

  • So we're going to require that Leiber We'll just call it monkeys and we're gonna type in, require Mongoose, which again is going to require the library Montagues and why was to set it up?

  • The next thing we need to do is actually connect or have a diet database soul type in Mongoose Connect, and we want to put in here the string which is our database connection and our case.

  • This is going to be mongo, D B colon, backslash, backslash.

  • And then it's going to be vocal house since we're on local host and then again slash And we want to type in whatever our database name is going to be called.

  • We're gonna call this subscribers because this is going to be a database that holds subscriber information, which is what I arrested a p I is going to handle.

  • And then after that's done, we can just save this and you could see down here we get this deprecation warning saying use new Europe are, sir, truth needs to be passed in because the old one is deprecate ID.

  • So what we can do is we can pass that option into the end of our connect just like this.

  • And now we say that you see that that one in message goes away and we have nothing else to worry about.

  • Also, what we can do is we can actually create a variable hell called D B, which going to be equal to mongers stock connection.

  • And from here we can hook up some events to run when our databases connected to so we know it's working correctly.

  • We could just say D b dot on and what we want to do is on error.

  • We want to log out that there's an air, so we'll just say here this is going to take a function with an air and we can come in here and say console dot there and we can pass it that air this'll just allow us to see if there's a problem connecting to our database.

  • Also, what we want to do is it Once we connect so well, say data D b dot once, which means it's only one runs.

  • And whenever we opened the database, what we want to do is we want to counsel that log saying that we opened the date of this so we could just say connected to database just like that.

  • And now when we say if we should get the message down here, same connected the database, and that's perfect.

  • But one thing that you'll notice immediately is that we have our mongo D B database string inside of our application, and when we deploy our application, we're going to want to use something that's not our local host, so we need to pull this out into an environment variable.

  • So let's remove this right here.

  • Go into our dot nd We could just create a variable, which we're going to call database you, Earl.

  • And we want to set that equal to Armando DVD library right here and now inside of our server.

  • We can come in here and use process dot e n v dot database euro or just whatever you name this inside of your diet and the folder, and this will pull from our diet envy.

  • We'll notice we get an error, and that's because we need to use the Dottie Envy Library.

  • It's all the way.

  • The beginning, we can say, require Dottie envy and all we need to do after require this is called a confit method.

  • So just say, dot com fig.

  • And this is going to load all of our environment variables from our Dottie envy.

  • Now, when we say that you'll see we no longer getting air down here and it says we connected to our database successfully.

  • So now we have a database completely done, our service completely hooked up in listening.

  • All we need to do is actually create routes for our server and also set up our server to accept Jason.

  • So let's first set up our servitude.

  • Except Jason.

  • We can just say after use, which will allow us to use any middle where that we want, which is essentially code that runs when the server gets a request.

  • But before it gets passed to your routes.

  • And what we want to do is we want to use express dot Jason and it's essentially just lets our server except Jason as a body inside of a post element or get Omer whatever.

  • Also, what we want to do is we want to set up our routes.

  • So since we're going to have a subscriber, FBI, we're going to have some routes that are gonna be called subscribers grounds Subscribers Router never get lips.

  • I cannot spell subscribers.

  • Writer.

  • There we go.

  • This is going to route all of our subscriber information.

  • We could just say require and this is going to be inside of a folder inside of her application called Routes.

  • And it's just going to be called subscribers so we can create that.

  • Now.

  • Let's create new folder.

  • This is going to be called grabs.

  • And inside of this folder we want to create a file which is going to be called subscribers dot Js.

  • It just needs to match the name that we added in here for subscribers right here.

  • Now, once we have that, we can go in here and tell our app that we want to use that round so we can say app that use We pass it the path we want, which in our case, we want to use this whenever we query subscribers.

  • So are you are always gonna look like this local host 3000 slash subscribers.

  • And this is going to be right here, this euro, everything that has this euro or anything after it is going to go into this subscribers router which we created right here.

  • So now that we have that done, we need to actually tell it.

  • We want to use the subscribers Ratter, and then we go, our application is set up and working, and you'll see that we get an air.

  • And this is because our router dot use requires middle.

  • Where this subscriber writer right now is absolutely nothing.

  • This is completely blank.

  • So let's set that up.

  • We again, I need to use expressed.

  • So we're going to say require express in here.

  • This is because our entire application uses express.

  • And what we want is we want the router portion of express.

  • So we could just say express dot Browder And this is going to get us the router from expression.

  • And for now, all we want to do is export that so we can save module exports is going to equal to router.

  • This is just going to fix our errors down here.

  • And as you can see, we no longer get any errors.

  • Everything's working fine.

  • But we have no routes actually configured yet, since it is going to be a rest, Phillipe, I we're going to use rest ful in points.

  • And if you don't already have a strong grasp of what rest is and what rest will end points are I have a really short video going over arrest in depth, which you can check out in the cards and the description like below.

  • So now let's start creating our different routes.

  • We're going to want some routes for getting all subscribers were gonna want a route for getting one.

  • We're also gonna want a route for creating one.

  • We're gonna want a route for updating the single one hopes updating one.

  • And we're also going to want around here for the leading one.

  • And let's configure those wraps To do that, we could just say router dot Get for example, which is going to be get.

  • And to get all we just want to use this Blake path right here.

  • And of course, all these are going to take a request and the response, and that is going to be a function.

  • And inside of here, we're going to do all of our code for our different routes.

  • So what's bit all of these rocks created?

  • Forgetting one.

  • We're going to want an I D in here and with a colon in front of it like this.

  • This means that this is a parameter that we can access by typing and request dot Karim's And this would be wolves grams dot i D.

  • And this would give us access to whatever they pass in after the first slash.

  • Next, we want to create our create route, and this is going to be a post instead of agate.

  • So we can say dot post and again, we're not going to need an I d here.

  • Since they're not actually going to be creating it with an I.

  • D.

  • They're going to be creating it on just the general route.

  • Next, we need to do update so coming down here and we're going to be using patch instead of put for update because we only want to update based on what the user passes us.

  • If they only pass us the name of the subscriber, we only want to update the name and none the other information about the subscriber.

  • Because if we used put, it would update all the information of describe her all at once instead of just the information that gets passed.

  • Now, lastly, we want to create our delete route.

  • What is going to be extremely stuff explanatory?

  • This is just going to be a delete.

  • And again, we need an I d.

  • Here as well as on the pad trout.

  • We're going to need an i d.

  • And this is the basic shell of all the different routes that we're going to create now, in order to test these routes.

  • What's great in here?

  • Just a rez dot send, which is just going to send text down to the server.

  • I was gonna say hello, world.

  • So we know that we actually have called this Get out here for getting all of our subscribers.

  • And normally, to test these, you may go into the browser and open it up, but you can't really test arrest a guy very well in a browser because you have nothing to interact with.

  • So what we're going to use is we're going to use an extension in visual studio code, and this extension is called right here.

  • Rest client has two million downloads is incredibly great, and it allows you to call arrested guy directly from visual studio code.

  • You can also use a program such as postman if you want to instead.

  • But I really like being able to do this directly in visual studio code.

  • So we're going to do is we want to create a path here.

  • A file which is going to be should be called route dot rest.

  • You can call it whatever you want.

  • It just has to end in either dot rest for dot http.

  • And in here we can create our requests.

  • In our case, we want to create a give request and we want this.

  • Get request to go to http slash slash local host 3000 that we wanted to be in the subscribers.

  • So we're going to say slash subscribers clips that added a little bit more than I wanted.

  • And this is actually going to request that route that we just set up right here or get all route.

  • And what we can do is we just click send request and it's going to send that request.

  • And as you see, we get a hello world back at the top.

  • Here we have all the different headers and statuses.

  • We can pretty much ignore this for the most part, but down here is going to be the actual content of the request that we get said.

  • So as you can see right here we got hello world.

  • And if we go into this one, we can do residents send and we want to send the request dot programs that I d, for example and we can make a request to that in our rob start rest.

  • We can even do multiple.

  • So if we just add in here three hashtags and then we do another route, this will separate these into two different requests and we can do an idea.

  • Let's say 12.

  • For example.

  • We click send on.

  • We get that i d 12 back, change it to 15 and we get 15 back.

  • So we know that a routing is working and we're able to call it directly from visual studio code.

  • Now, with all that out of the way, what's actually create our model that we're going to use for application so we can create a folder called Models, which is going to hold our model, which is going to be a subscriber model.

  • So it was called Subscribing Js, and in here we're going to be using monkeys.

  • So we're going to require Mongoose.

  • Call it manga Sequels require and again, Mongoose, this is going to allow us to create a model which we can use to interact with the database in a really easy way.

  • So what we want to do is we want to create a schema.

  • We're just going to call this our subscriber schema cannot spell every time we're gonna set this equal to a new mongoose dot schema and this is going to take in here a judge javascript object and the object is going to have keys for all the different properties of our subscriber.

  • In our case, we're going to have a name, and this is going to have an object, is the value will food and later it's going to have a subscribed to channel.

  • So this is who the user is subscribing to, which again, we're gonna fill in the details later.

  • And lastly, we're gonna have a subscribe close subscribe date, and this is just going to be the date that they subscribe to the Channel.

  • And again, this is going to take all you in here and it looks like I spoke this incorrectly.

  • There we go.

  • And what we want to do instead of here, is actually to find the different properties for our scheme it.

  • So we want to put the type.

  • In our case, the name is going to be a type of string, and we always want the name to be required.

  • So we're just going to have required true here.

  • We're going to do the exact same thing for the subscribe to channel.

  • It's going to be a string, and it's always gonna be required.

  • And then lastly, we have our date.

  • This is going to be a type of dates.

  • It's goingto have a required of true as well because we always want to have the date they subscribed.

  • But lastly, we want to default this.

  • So we're gonna use here default, and we want to set this to date dot now.

  • So if we don't pass, those described a issues going to default it to the current date.

  • Now, with that scheme like created, we could go down here.

  • We can export that so we can say modules module that exports.

  • We want to set that equal to mongoose dot model.

  • And now this model function takes two properties.

  • The first is the name of the model in our database.

  • In our case, we're gonna call it Subscriber and the next is the scheme it that corresponds that model, which in our case is subscribe your schema and the reason we need this model function is because when we export this an imported in a different file, this model allows us to interact directly with the database using this schema, which is perfect.

  • So now let's save that go into our subscriber dot Js here, and we can include that.

  • So we can say subscriber is going to be equal to require we want to require back one folder in the model U models folder subscriber.

  • And now this is going to pull in our subscriber, which were created in this model here.

  • And this is where the fun really begins.

  • So let's do our first to get all route because this is about the easiest one.

  • We're going to use a single weight in order to do this.

  • So if you don't understand a single week, I have a video link in the cards and description, which you can check out.

  • But essentially what we're going to do is we're gonna wrap this all gonna try to catch just like this and inside the try, we're going to get all of the different subscribers for our model.

  • So we're gonna say constant subscribers is going to be equal to our subscriber model, not find, and this is just going to get old, the different subscribers and we need to make sure we await this because this is an asynchronous method.

  • So if we await this as soon as it's on executing, we're going to get all the subscribers here in this method.

  • But if, for example, there's an error, we want to make sure that we catch that air.

  • So if there isn't error, we want to send that to the user.

  • And we want to send it as Jason because this is a Jace on a P I.

  • And here we're just going to send a message, which is going to be error dot message just like that.

  • And we also want to make sure we set this status so the user and know that it was failure so we can say dot status.

  • And here we want to send the status code.

  • In our case, we're gonna send a status code of 500 now, 500 standards to code means that there's an error on your server.

  • It means that the actual server in our case, our database had some kind of air which caused the actual transaction not to work.

  • And I had nothing to do with the actual user or client using the AP.

  • I it was entirely our fault.

  • That's what 500 means And any Eric Oh, that's in the 500 range needs that.

  • Now.

  • If we actually were successful.

  • We want to send this using Jason.

  • We just want to send all the subscribers to the user.

  • Now, we can go in here, we can test our route and we should get back just in empty array.

  • And as you can see, that's exactly what we get.

  • We get an empty array because we have no subscriber ship.

  • So let's create our create route so we can actually add subscribers and see what it looks like.

  • We'll scroll down to that and we're also gonna make this an asynchronous function because we're going to be trying to save that model, which is an asynchronous operation.

  • So we want to create a variable called Subscriber said it equal to new subscriber.

  • And this is just going to take a Java script object.

  • First thing we want us, that is the name, and this is going to come from the request from the body.

  • So the body is whatever the user sends to us, which is going to be Jason, and we want to get the name property of the body.

  • We want to do the same thing with the subscribed to channel, and we want to set this to the request from that body, not subscribe to Channel.

  • And let's close on this request here.

  • And there we go.

  • That's our subscriber created.

  • But now we actually need to save that, and that's where the asynchronous part comes in.

  • So we're just gonna wrap this in a track catch again, and we want to catch that air, of course.

  • And inside of the tri here, what we want to do is we want to try to save our subscriber.

  • So we're gonna save new subscriber is going to be equal to a waiting the subscriber, which we just created that safe, and this is going to try to persist that to the database.

  • And if it's successful, it's going to put it into this new subscriber variable.

  • And if it is successful, we want to send this to our user using Jason.

  • So we'll say new subscriber, and we also want to set a specific status here.

  • We want to set a status of 201 and the status to a one means successfully created an object by default.

  • If you don't send any status, it sends a status that 200 which means everything was successful, but to a one is just a more specific way to say that you created something.

  • So when you're using a post route, you always want to make sure to send to a one when you're successful instead of 200.

  • Now let's catch that air.

  • So we want to say resident status, and this time we're going to send a status of 400 set of 500.

  • And this is because our thing is going to fail here.

  • If the user doesn't pass in the name where they don't pass in a subscribe channel, for example, so if the user gives us bad data, it will fail.

  • And whatever the user gives you bad data.

  • The client.

  • You want to send a 400 error because that means there's something wrong with the user input and not something wrong with your server.

  • And, of course, we want to send that message to them.

  • So we'll say dot Jason air dot message.

  • And of course, we want to make sure we wrap this in an object just like that, and then we go, we can save that.

  • And now let's actually test that So damn in here make sure you put in our three hashtags.

  • We want to do a post route and we want a post to essentially the same exact place.

  • Http local host 3000 subscribers And that's exactly perfect.

  • And now to send data to it, we had to make sure we leave a blank line here, but and then here we can put our Jason.

  • So what?

  • Type it in.

  • We want to send a name, hopes to make sure it's in quotes name and we want this person to be amazing.

  • Person is their name, and this subscribed to channel.

  • What's type that out quickly subscribed to Channel is, of course, going to be wept have simplified because all of my subscribers are amazing.

  • People lived of simplified and there we go.

  • And now that we want our server to know that this is going to be Jason, that we sent to it.

  • So we need to set the content type to be adequate.

  • Application slash Jason.

  • Now we can click send request and you'll see that we get a message.

  • It's a subscriber of elevation.

  • Failed subscriber to Channel path subscriber channel is required and this means I spelled something wrong.

  • I spelled subscribed to channel as subscriber to channel.

  • So let's see where I did that.

  • We could just do a search.

  • All hit, enter and it looks like in here and our schema.

  • I just misspelled this.

  • It should be subscribed to channel instead of subscriber to channel.

  • Now let's go back and test our route.

  • We can click send request again and you see that we get our model back.

  • It has an automatically generated I D as well as the name subscribed to channel and subscribed it, which you can see it's set to whatever the current date that I'm recording, this is.

  • And if we don't pass in the name, for example, and we hit send request, we're going to get back that error message and you'll also notice we get that 400 sets which says bad request, which is perfect because it will come back as an error to the user using our a p I.

  • Let's put that back to how it was.

  • So we have is successfully working a p I.

  • Now let's go back to our out here and you may notice that all of the rest of our routes are going to be taking an i.

  • D.

  • Our update, our delete as well as our get all have an idea that we're going to pass to it, and they're all going to do the exact same code of the beginning in order to get the subscriber.

  • So instead of writing that code in every single one of our routes, we're gonna use what's called a middle where So we're gonna create a function which will be that middleware.

  • And these functions have the exact same syntax as this function right here.

  • We're gonna call this one, get subscriber because essentially, that's all it's going to do.

  • It's kind of taken I d and get us a subscriber.

  • And as I mentioned, it has a request response.

  • And next as the final property and essentially all that this next function does is this says if we call this move on to the next section of our code, which is going to be this callback right here, Mrs what The middle, where is.

  • And of course, we're gonna make this a synchronous because we're going to be accessing the database inside of this coat.

  • And now, of course, we want to wrap everything instead of a try catch.

  • So put the try right here.

  • And of course, we want to catch our air.

  • And now inside of his tribe, we want to get up, Subscriber.

  • So we're just going to say subscriber is going to be equal to a waiting this subscriber dot find by i d.

  • And this All we have to do is pass an idea which, as you remember, I said that request dot programs dot i d is going to be the correlating to the variable that they passed inside of the route here.

  • So this is going to try to get a user based on the idea that they pass us inside of the girl.

  • And then what we can do is we can check to see if that subscriber actually exist.

  • So we can say subscriber equals No.

  • So if this group scribe er does not exist, we want to do is we wanna return here and we want to set the status right here to be equal to 404 and a 44 status means that you could not find something and which is exactly what happened in our case, We're not able to find this prescriber.

  • And then, of course, we want to send back a message to the user knows that.

  • What?

  • So we'll send back a message here, and this message is just going to say, cannot find subscriber.

  • There we go.

  • Now we have out of the way what's actually create our subscriber of here.

  • We're gonna defaults to undefined.

  • And what we want to do is we want to set our response dot subscriber.

  • This is just a variable worker creating on the response object.

  • We're going to set that equal to subscriber and this way, inside of all of these other functions, we can just call rez dot subscriber right here.

  • And this is going to be the subscriber that we set down here.

  • So let's leave that now.

  • And the reason we're calling return here is because if there is no subscriber, we want to immediately leave this function and no longer go any further.

  • And inside of this catch here, we just want to do essentially the same thing we want to do.

  • We return.

  • We want to set the status.

  • This case is going to be a 500 because there's something wrong with our surfer.

  • That's causing this problem.

  • And we want to send that message back to the user.

  • We're gonna say message is going to be equal to a red hot message just like that, which is perfect.

  • And then, lastly, that next function we want to call all the way down here because we successfully completed this entire get subscriber function so next will allow us to move on to the next piece of middle, where or the actual request itself.

  • So now let's use that get subscriber metal where we'll go up here and all you do is put it before your actual function.

  • You don't actually call it.

  • You just put the name of that function right there, and that'll be your entire middle where set up now instead of here.

  • We can say that we want to send the request response dot subscriber dot name, for example.

  • And if we say that since we have this gift subscriber in here, this is actually going to get the name of the subscriber and send it back to us.

  • It's just for testing purposes, So let's get all of our subscribers here.

  • We'll send a request.

  • We're gonna take an i.

  • D.

  • We want to use that instead of this request to get a single subscriber.

  • And if we quick on that, you'll see that we get the name of that subscriber, which is amazing person.

  • And that's perfect.

  • If, for example, we send a different I D which does not exist and we click send, you'll see we get a message.

  • This is cannot find subscriber.

  • So we know that our middle, where that we've created is working.

  • So now we can apply that middle where to the rest of all of our routes.

  • So it's copy this stone do this inside of here and we also want to do this inside of here Friday leading Let's exit on this So we have a little bit more room to work with, and now we can actually create our route right here forgetting one.

  • And this is really straight for all we want to do is send that actual subscriber.

  • So we'll say rez dot hopes not raised a Jason Read Stop subscriber, and this is just going to send us a Jason version of that subscriber.

  • And of course we can try calling that right here and you'll see we get the Jason version of that back, which is perfect.

  • Now back to our rubs.

  • We can work on the delete route because that one's also really straightforward.

  • We want to make sure this is a synchronous because we're going to be calling this using try, catch.

  • So what's so that tried catch just like that?

  • And we, of course, want to be able to catch an error in here.

  • If something, for example, happens and inside of here, all we want to do is we just wanna wait reds dot subscriber dot remove.

  • This is just going to try to remove that subscriber from the database.

  • And if it fails, we're going to get an error down here, which we can just send back a status of 500 because something obviously is wrong on our end.

  • If we get an error trying to remove it, and would you want to send back the message as the era, that message.

  • And if we did successfully remove the subscriber, we could just send back some Jason that says that we did that so we could just stay in here.

  • We're gonna send a message that says deleted subscriber.

  • So I was trying to call that we could just come down here separated with three hashtags just like this.

  • Everyone I called elite and we just want to call it on the route of here for the user with the correct I D.

  • So let's copy that down and let's call send request and you'll see message deleted subscriber.

  • And if we try it again, you'll see cannot find subscriber because we deleted as prescriber.

  • And if we try to get all of our subscribers, we now get an empty array again because no more subscribers exist.

  • So let's send that request to add a new subscriber back.

  • So we have at least one subscriber here, as you can see inside of our database so we can use that with our new patch route that we're going to be creating now.

  • Now, in order to update, we need to do as I said, only update for things that actually are sent to us in the request.

  • So what we want to do is we want to check the request.

  • We can say if the request dob body that name is not equal to know.

  • So if the user actually passed a name to us.

  • We want to take that rez dot subscriber, and we want to set the name equal to the request dot body dot name, and we want to do the exact same thing.

  • What?

  • We're gonna do this for this?

  • Subscribed to channel.

  • So in here will tie pin, subscribe to channel, and we want to set the subscribe to channel to the subscribe to channel that's passed in.

  • Try saying that 10 times fast.

  • Now we can actually use the try catch down here in order to try to update our user.

  • We, of course, when I catch that air and inside of here, all we're going to do is we want to say this is going to be our updated subscriber looks subscriber is going to be equal to await rez dot subscriber, you're going to get our subscriber, and again we're gonna use that save function.

  • So this is going to give us the updated version of our subscriber if they successfully saved And then, of course, we can use resident Jason here in order to send back that updated subscriber.

  • And if we have an error, we can set the status here equal to 400 because again, if the user's pass in like a name that's not acceptable or subscribe to channel is not acceptable, that's their fault, not ours.

  • So we want to make sure we sent a 400 error instead of a 500 and we want to send in a message, which is just going to be error that message.

  • So now we can actually try testing that.

  • But before we do that, you can see we get an error.

  • And it says a weight is only valid in a sink functions.

  • So we need to just make sure that is an asynchronous function.

  • And now everything's green, which is perfect.

  • We can come in here.

  • It's just coffee.

  • This delete for now, put in three hashtags And we could just say here we want to do a patch and we want to patch this user.

  • We want to send application dot Jason as our content type, just like here.

  • And let's say we want to change the name so we're gonna set the name here, two new name, and now if we actually send this request, you'll see that it says it cannot find the subscriber with this I d And that's because this idea no longer exists.

  • So let's get a new a new I d.

  • From are currently existing subscriber.

  • You see, their name is amazing person, so we'll copy that idea paced it down here on our patch and we'll send that request.

  • And you see, we get back a new object here, which is the updated object, and has that new name.

  • And now if we query all of our subscribers, you see, this subscriber now has the name of new name and that's it.

  • The entire rest A p I is complete.

  • If you want to go deeper into no Jason Express, make sure to check out my completely free full stack course on YouTube, which is linked over here.

  • Also subscribe to the channel to not miss any more videos like this.

today we're gonna build your very first rest a p I as quickly as possible.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it