This lesson will demonstrate getting all documents from a view, loading a specific document, updating the document and then how to delete the document.
It will explain the difference between the PUT and PATCH HTTP calls for the Domino REST API and will demonstrate Domino Security working when trying to delete a document.
Instructor: [00:00] We're now going to demonstrate updating and deleting Domino data via the NodeJS server. To do that for our demonstration, we're going to need to add several routes. They're all fairly similar, so what I'll do is just highlight the differences.
[00:11] The first that we're going to need to do is get hold of a list of records. We're going to use this list in our demo just to be able to use select a document, which will then open up the data. Then it allows you to update it or delete it.
[00:27] Common to all these routes will be the need to have the Domino security token past. The options we need for the request to Domino are going to be, again, fairly similar across all our routes.
[00:42] In the case of a view of all records, which is past that as the last argument in our API code. Then we'll use our standard method for dealing with the response back from Domino, which will be to check for any security issues. I'll send through the data. I'll also handle any errors.
[01:10] That's our first route, which is to get all "Star Wars" records from a note's view. We're also going to need the following routes. We're going to need a route to get an actual individual document.
[01:22] This one is going to be past the unit off the record. Exactly the same, we're looking for Domino security. The options are very similar, except the URL is slightly different where we have documents/unit. We pass it the unit, which has been passed to the express application.
[01:42] When you have a route that looks like this with a colon you did in this case, that property becomes available to you through the Express framework using this syntax. Our request to Domino is exactly the same.
[01:56] That's an individual record. We now have to deal with the update to an individual document. There are two methods available to you or HTTP methods, I should say. There's the PATCH and a PUT.
[02:08] Now, according to the Domino REST API, if you use the PATCH method, you only need to pass the specific fields you want to update. Whereas the PUT method, you need to pass either all your fields, or if you don't, then the ones that you don't pass will be blanked.
[02:25] Therefore, I see no real value in the PUT method. I would stick to PATCH. To keep it the same on our Node server, we'll also use the PATCH HTTP method. Again, we'll be passed the unit of the document we want to update.
[02:44] Again, we'll be checking for Domino security. Now, our options for our request to Domino is slightly different. The key thing here is we have to set a special header for Domino called the XHTTP Method Override. It needs a PATCH as its value.
[03:01] The actual HTTP request to Domino will be a standard post. As part of our PATCH, we will be passing the body from the request and send that straight through to Domino. This can be a subset of fields.
[03:15] That will then update the Domino document, but it's critical. You must include this value as a HTTP header. The actual request to Domino itself is exactly the same as our other routes.
[03:27] Next, we'll add the Delete route. Again, we'll be passed the unit of the document we want to delete.
[03:33] We'll be using Domino security, so we need a token. Our options for our requested Domino are similar, except the method will be Delete and our actual request to Domino will be the same as the other routes.
[03:46] We've got get all records, get an individual record, update a single record, and delete a record. That's our service [inaudible] JS file updated of all the new routes. We'll now look at the index to our HTML page, which we'll use to show how it all hangs together.
[04:07] Here, we have our web page, which we're going to use to display our records and edit them and then delete them. Standard bootstrap layout -- we've got a top form, which we'll use to do the login, seen before on this one.
[04:19] Then we've got a container, which is going to hold a list of our records. Then finally, we have a bottom form, which we'll be using to do the updating of the data. Down the bottom, we have our script functions.
[04:34] Now, I should point out that this demo is using no libraries, whatsoever. There's no jQuery or no AngularJS, no React, no View. All this stuff would be much easier using a single-page application.
[04:59] We have a function to load records. This will be calling our Get on our Node server, which is the SW records route. Once we get back the information, we're going to loop over it and update our list element with a list of links.
[05:14] Clicking on a link we'll call the Load Record function, passing it the unit of the selected record. This is engulfed to our Node server. Using the SW record/unit route, it will get the data. It will then update the form for it to be editable.
[05:29] We then have our update function. This one will do the update by sending a PATCH HTTP method to the Node server, passing it the unit. The last one is we got a Delete method.
[05:43] This again is very similar where we're just calling our SW records with the unit and we're passing it a Delete HTTP method. One thing we're doing is to hold the unit value for the selected record as a hidden input field on the form.
[05:57] Let's have a look and see what it looks like in the browser. I've started my server, refreshed my browser page, loaded up my new HTML page, which is to be records. The first thing I'm presented with is the login.
[06:08] I'm going to log in to Domino via my Node server. Successfully logging in. The next thing that happens is the call to going to get to the note's view. You'll see here, we're actually getting back a response, which is Domino data which corresponds to this list element up here.
[06:23] If I click on one of these, I then populate my form. Using the Update method here, I can change a value.
[06:31] If I click update, it's going to go off and do a patch to Domino. The end result is actually updated automatically up here, because my view is being refreshed as well.
[06:43] Finally, just to prove I'm using Domino data, I've turned off the ability to delete from my username. If I click delete, I get an error, coming back from Domino saying I'm not authorized to perform the operation because in Domino, I'm not authorized to delete documents.
[06:59] If I click delete documents, I go back into the browser. Try again. The document is deleted. That's the code working.
[07:09] As I say, click on the document. Load it up into the form. You can edit it, update it, and delete it.