title
Build a Custom URL Shortener Service

description
In this project, we will build an API to shorten URLs, like Bitly. We will use Node.js/Express/MongoDB to store the long, short and url code for each. Code: https://github.com/bradtraversy/url_shortener_service Sponsor: DevMountain Bootcamp https://goo.gl/6q0dEa 💖 Become a Patron: Show support & get perks! http://www.patreon.com/traversymedia Follow Traversy Media: https://www.facebook.com/traversymedia https://www.twitter.com/traversymedia https://www.instagram.com/traversymedia

detail
{'title': 'Build a Custom URL Shortener Service', 'heatmap': [{'end': 1928.541, 'start': 1902.829, 'weight': 1}], 'summary': 'Learn to build a url shortener service using node.js, express, and mongodb, with steps for setting up a basic express server, connecting to a mongodb database, creating short urls and routes, validation, implementing a url shortening api, and creating new endpoints for a url shortening service.', 'chapters': [{'end': 727.732, 'segs': [{'end': 89.014, 'src': 'embed', 'start': 62.78, 'weight': 0, 'content': [{'end': 68.543, 'text': "But in this video, we're going to build the API basically so that we can get this functionality.", 'start': 62.78, 'duration': 5.763}, {'end': 73.466, 'text': 'We can send a long URL and get back a short URL that will actually work.', 'start': 68.603, 'duration': 4.863}, {'end': 82.611, 'text': "And we're going to be using a database because we need to store the long URL, the short URL, and the code, which is basically this part here.", 'start': 74.206, 'duration': 8.405}, {'end': 85.612, 'text': "So I'm using MongoDB for that.", 'start': 83.631, 'duration': 1.981}, {'end': 89.014, 'text': "We're going to use MongoDB Atlas, which is the cloud version.", 'start': 85.912, 'duration': 3.102}], 'summary': 'Building an api to shorten long urls using mongodb atlas.', 'duration': 26.234, 'max_score': 62.78, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ62780.jpg'}, {'end': 223.623, 'src': 'embed', 'start': 191.976, 'weight': 1, 'content': [{'end': 196, 'text': "OK, so expresses the web framework we'll be using to create our routes and stuff.", 'start': 191.976, 'duration': 4.024}, {'end': 203.546, 'text': "We're going to use node config, or config, which is just a package that allows us to have global variables.", 'start': 196.48, 'duration': 7.066}, {'end': 212.734, 'text': "We're going to be using Mongoose, which is an abstract, basically like an abstraction for our database so that we can easily interact with MongoDB.", 'start': 204.086, 'duration': 8.648}, {'end': 217.197, 'text': "We're going to use a package called short ID to generate the URL code.", 'start': 213.214, 'duration': 3.983}, {'end': 223.623, 'text': "And we're going to use valid-url to validate the URLs that are sent to the API.", 'start': 217.618, 'duration': 6.005}], 'summary': 'Using node config, mongoose, short id, and valid-url for web development.', 'duration': 31.647, 'max_score': 191.976, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ191976.jpg'}, {'end': 702.303, 'src': 'embed', 'start': 668.689, 'weight': 2, 'content': [{'end': 671.23, 'text': "And let's see, we're going to bring in Mongoose.", 'start': 668.689, 'duration': 2.541}, {'end': 681.018, 'text': 'And then we want to create a schema.', 'start': 679.218, 'duration': 1.8}, {'end': 684.299, 'text': "So we're going to call this URL schema.", 'start': 681.078, 'duration': 3.221}, {'end': 689.32, 'text': 'And we set this to a new mongoose dot schema.', 'start': 684.839, 'duration': 4.481}, {'end': 693.861, 'text': 'And then this takes in an object with all the fields we want.', 'start': 690.02, 'duration': 3.841}, {'end': 696.002, 'text': 'So first thing is a URL code.', 'start': 693.921, 'duration': 2.081}, {'end': 699.042, 'text': "And that's going to be string.", 'start': 697.242, 'duration': 1.8}, {'end': 702.303, 'text': 'We also want a long URL.', 'start': 700.163, 'duration': 2.14}], 'summary': 'Creating a url schema with mongoose for a web application.', 'duration': 33.614, 'max_score': 668.689, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ668689.jpg'}], 'start': 7.059, 'title': 'Building a url shortener service', 'summary': 'Covers building a url shortener service using node.js, express, and mongodb, with steps including setting up a basic express server, connecting to a mongodb database, and creating a mongoose model for url schema.', 'chapters': [{'end': 727.732, 'start': 7.059, 'title': 'Build a url shortener service', 'summary': 'Discusses building a url shortener service using node.js, express, and mongodb, including setting up a basic express server, connecting to a mongodb database, and creating a mongoose model for url schema.', 'duration': 720.673, 'highlights': ['The chapter discusses building a URL shortener service using Node.js, Express, and MongoDB. It covers the process of creating a URL shortener service and the technologies used, including Node.js, Express, and MongoDB.', 'Setting up a basic Express server and connecting to a MongoDB database. It includes initializing an Express app, adding middleware to accept JSON data, setting up a port variable, and connecting to a MongoDB database using Mongoose and a config package.', 'Creating a Mongoose model for URL schema, including defining fields like URL code, long URL, short URL, and date. It involves creating a Mongoose schema for the URL, defining fields such as URL code, long URL, short URL, and date to be used for the URL shortener service.']}], 'duration': 720.673, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ7059.jpg', 'highlights': ['The chapter discusses building a URL shortener service using Node.js, Express, and MongoDB.', 'Setting up a basic Express server and connecting to a MongoDB database.', 'Creating a Mongoose model for URL schema, including defining fields like URL code, long URL, short URL, and date.']}, {'end': 1019.048, 'segs': [{'end': 774.506, 'src': 'embed', 'start': 728.613, 'weight': 0, 'content': [{'end': 731.058, 'text': 'And then we just want a module dot export.', 'start': 728.613, 'duration': 2.445}, {'end': 732.761, 'text': 'So we want to export the model.', 'start': 731.078, 'duration': 1.683}, {'end': 740.114, 'text': 'So we say mongoose dot model and name of the model is URL.', 'start': 732.901, 'duration': 7.213}, {'end': 741.857, 'text': 'And then we need to pass in the schema.', 'start': 740.154, 'duration': 1.703}, {'end': 743.932, 'text': "OK, and that's it.", 'start': 743.331, 'duration': 0.601}, {'end': 744.813, 'text': "Let's save that.", 'start': 743.992, 'duration': 0.821}, {'end': 746.034, 'text': "So that's our model.", 'start': 745.153, 'duration': 0.881}, {'end': 749.157, 'text': 'Now we need to start to deal with our routes.', 'start': 746.835, 'duration': 2.322}, {'end': 757.126, 'text': "So we're going to have a folder called Routes, basically just going to have two routes, but I'm going to have two separate files.", 'start': 749.878, 'duration': 7.248}, {'end': 763.193, 'text': 'One is going to be index.js and then one is going to be, excuse me, url.js.', 'start': 757.246, 'duration': 5.947}, {'end': 774.506, 'text': "So URL.js is basically where we're going to have our post route to be able to create a URL and insert it into the database.", 'start': 765.718, 'duration': 8.788}], 'summary': "Creating a model named 'url' using mongoose, and setting up routes for creating and inserting urls into the database.", 'duration': 45.893, 'max_score': 728.613, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ728613.jpg'}, {'end': 915.145, 'src': 'embed', 'start': 876.297, 'weight': 2, 'content': [{'end': 881.082, 'text': "This is where we we actually create our short URL that's going to have that route.", 'start': 876.297, 'duration': 4.785}, {'end': 885.005, 'text': "So we're going to bring in a couple of things here.", 'start': 881.802, 'duration': 3.203}, {'end': 893.092, 'text': "So we're going to bring in our valid URL method that comes from that valid URL package that I installed.", 'start': 886.086, 'duration': 7.006}, {'end': 898.117, 'text': "So it's valid dash URL.", 'start': 894.814, 'duration': 3.303}, {'end': 902.539, 'text': "uh, let's see, let's also bring in our short id.", 'start': 899.698, 'duration': 2.841}, {'end': 905.401, 'text': 'so what is it?', 'start': 902.539, 'duration': 2.862}, {'end': 915.145, 'text': "it's short id, like that short id, and then let's also bring in.", 'start': 905.401, 'duration': 9.744}], 'summary': 'Creating a short url with valid url package and short id.', 'duration': 38.848, 'max_score': 876.297, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ876297.jpg'}, {'end': 988.746, 'src': 'embed', 'start': 949.698, 'weight': 4, 'content': [{'end': 960.892, 'text': "And this is going to be a I'm sorry, it's going to be a post request on a poet, a post request to slash API slash.", 'start': 949.698, 'duration': 11.194}, {'end': 963.494, 'text': 'URL slash shorten.', 'start': 961.833, 'duration': 1.661}, {'end': 967.035, 'text': "OK, that's going to be the end point to create a short URL.", 'start': 963.694, 'duration': 3.341}, {'end': 969.837, 'text': "And let's just give this a description.", 'start': 967.596, 'duration': 2.241}, {'end': 976.139, 'text': 'Say create short URL.', 'start': 972.518, 'duration': 3.621}, {'end': 984.623, 'text': "OK So let's go ahead and take our router and.", 'start': 980.001, 'duration': 4.622}, {'end': 988.746, 'text': "Let's say router dot post because this is a post request.", 'start': 985.765, 'duration': 2.981}], 'summary': 'Creating a post request to shorten urls using the api endpoint slash shorten.', 'duration': 39.048, 'max_score': 949.698, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ949698.jpg'}], 'start': 728.613, 'title': 'Creating short urls and routes', 'summary': "Involves setting up a mongoose model for url and defining two routes, index.js and url.js, for creating short urls and redirecting to long urls. it also explains the process of creating short urls and routes using valid url package, short id, config, and url model, while also creating a post request endpoint '/api/url/shorten' to create a short url.", 'chapters': [{'end': 876.257, 'start': 728.613, 'title': 'Setting up mongoose model and defining routes', 'summary': 'Involves setting up a mongoose model for url and defining two routes, index.js and url.js, for creating short urls and redirecting to long urls. it also includes setting up routes in main index.js using express router.', 'duration': 147.644, 'highlights': ['Setting up a Mongoose model for URL by exporting the model using mongoose.model and passing in the schema.', 'Defining two routes, index.js and url.js, for creating short URLs and redirecting to long URLs.', "Setting up routes in main index.js using express router by defining app.use for '/' and '/api/url' to pertain to the respective URL routes."]}, {'end': 949.678, 'start': 876.297, 'title': 'Creating short urls and routes', 'summary': 'Explains the process of creating short urls and routes using valid url package, short id, config, and url model, while also utilizing route signatures.', 'duration': 73.381, 'highlights': ['The process involves bringing in a valid URL method from the valid URL package, a short id, config, and the url model from the models directory.', 'The chapter details the creation of route signatures for the short URLs.', "Utilizing the valid URL package's method and short id to create short URLs is a key aspect of the process."]}, {'end': 1019.048, 'start': 949.698, 'title': 'Creating short url endpoint', 'summary': "Explains the process of creating a post request endpoint '/api/url/shorten' to create a short url, using 'router.post' method and destructuring to extract data from the request body.", 'duration': 69.35, 'highlights': ["The chapter explains the process of creating a post request endpoint '/API/URL/shorten' to create a short URL.", "The method 'router.post' is used to define the post request for creating a short URL endpoint.", 'Destructuring is utilized to extract data from the request body.']}], 'duration': 290.435, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ728613.jpg', 'highlights': ['Setting up a Mongoose model for URL by exporting the model using mongoose.model and passing in the schema.', 'Defining two routes, index.js and url.js, for creating short URLs and redirecting to long URLs.', 'The process involves bringing in a valid URL method from the valid URL package, a short id, config, and the url model from the models directory.', 'The chapter details the creation of route signatures for the short URLs.', "The chapter explains the process of creating a post request endpoint '/API/URL/shorten' to create a short URL."]}, {'end': 1227.694, 'segs': [{'end': 1084.11, 'src': 'embed', 'start': 1019.488, 'weight': 1, 'content': [{'end': 1021.83, 'text': "So we're just basically going to send a long URL.", 'start': 1019.488, 'duration': 2.342}, {'end': 1022.25, 'text': "That's it.", 'start': 1021.87, 'duration': 0.38}, {'end': 1024.372, 'text': "That's all we're going to send with the request.", 'start': 1022.611, 'duration': 1.761}, {'end': 1033.325, 'text': "And for our base URL, Let's set a variable of base URL, and let's get that from our config file.", 'start': 1025.353, 'duration': 7.972}, {'end': 1040.188, 'text': 'So config.get, and we want to get base URL, which is going to be, in our case, local host.', 'start': 1033.425, 'duration': 6.763}, {'end': 1041.468, 'text': 'Oh, wait a minute.', 'start': 1040.808, 'duration': 0.66}, {'end': 1048.3, 'text': "I put 3,000, didn't I? Should be 5000 because that's what I'm running it on.", 'start': 1041.488, 'duration': 6.812}, {'end': 1050.222, 'text': "Whatever port you're running it on.", 'start': 1048.801, 'duration': 1.421}, {'end': 1051.163, 'text': 'So you want to use.', 'start': 1050.422, 'duration': 0.741}, {'end': 1052.844, 'text': 'All right.', 'start': 1051.183, 'duration': 1.661}, {'end': 1055.006, 'text': "So let's see.", 'start': 1053.185, 'duration': 1.821}, {'end': 1057.448, 'text': "Let's make sure the URL is valid.", 'start': 1055.046, 'duration': 2.402}, {'end': 1068.358, 'text': "So to put an if statement here and we're going to use valid URL, which has a method called is you are I.", 'start': 1057.989, 'duration': 10.369}, {'end': 1072.963, 'text': "Okay, so basically it'll just make sure it's a valid URI or URL.", 'start': 1069.241, 'duration': 3.722}, {'end': 1076.085, 'text': 'And we want to check the base URL first.', 'start': 1073.323, 'duration': 2.762}, {'end': 1082.369, 'text': 'And wait a minute.', 'start': 1077.746, 'duration': 4.623}, {'end': 1084.11, 'text': "If it's valid.", 'start': 1083.069, 'duration': 1.041}], 'summary': 'Setting base url variable from config file, validating url.', 'duration': 64.622, 'max_score': 1019.488, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ1019488.jpg'}, {'end': 1155.705, 'src': 'embed', 'start': 1119.871, 'weight': 0, 'content': [{'end': 1123.692, 'text': "OK, and we're going to use that short ID package to do that.", 'start': 1119.871, 'duration': 3.821}, {'end': 1127.413, 'text': "So let's say create URL code.", 'start': 1124.292, 'duration': 3.121}, {'end': 1130.894, 'text': "So we'll say const URL code.", 'start': 1128.033, 'duration': 2.861}, {'end': 1139.091, 'text': 'And all we have to do is say short ID dot generate and that will create it for us.', 'start': 1131.854, 'duration': 7.237}, {'end': 1148.559, 'text': "Now we want to do is check the long URL that's sent in from the client and make sure that that's an actual URL.", 'start': 1140.772, 'duration': 7.787}, {'end': 1153.844, 'text': "So let's say check long URL.", 'start': 1148.599, 'duration': 5.245}, {'end': 1155.705, 'text': 'Actually, we put a comment here.', 'start': 1154.324, 'duration': 1.381}], 'summary': 'Using short id package to generate url codes and validate long urls.', 'duration': 35.834, 'max_score': 1119.871, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ1119871.jpg'}, {'end': 1227.694, 'src': 'embed', 'start': 1197.48, 'weight': 4, 'content': [{'end': 1206.855, 'text': "And let's see, I also want to mark this async, this route callback async because I'm using a sync await for Mongoose.", 'start': 1197.48, 'duration': 9.375}, {'end': 1215.471, 'text': "So let's do I'm going to use let here and create a variable called URL and set this to a weight.", 'start': 1207.636, 'duration': 7.835}, {'end': 1217.912, 'text': "And then we're going to take our model.", 'start': 1216.312, 'duration': 1.6}, {'end': 1221.753, 'text': 'So with Mongoose, we have a bunch of different methods.', 'start': 1218.912, 'duration': 2.841}, {'end': 1227.694, 'text': 'One of them is find one which will find one record from your database.', 'start': 1221.873, 'duration': 5.821}], 'summary': 'Code is marked async for mongoose sync await, with find one method to find a record.', 'duration': 30.214, 'max_score': 1197.48, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ1197480.jpg'}], 'start': 1019.488, 'title': 'Url shortener implementation', 'summary': 'Explains the process of validating and shortening urls, setting base url from a config file, and implementing code logic using short id package and mongoose, emphasizing async operations and error handling.', 'chapters': [{'end': 1119.171, 'start': 1019.488, 'title': 'Url request and validation in code', 'summary': 'Explains the process of sending a long url request, setting the base url from a config file, validating the url, and generating a code based on the bitly website link.', 'duration': 99.683, 'highlights': ['The process involves sending a long URL request and setting the base URL from a config file.', "Validating the URL using the method 'isValidURL' to ensure it's a valid URI or URL.", 'Generating a code based on the Bitly website link for the long URL.']}, {'end': 1227.694, 'start': 1119.871, 'title': 'Url shortener code logic', 'summary': 'Covers the implementation of a url shortener code logic using the short id package, validating a long url, and checking for its existence in the database using mongoose, with an emphasis on async operations and error handling.', 'duration': 107.823, 'highlights': ['The implementation of URL shortener code logic using the short ID package.', 'Validation of long URL using the valid URL dot is URI function.', 'Checking for the existence of the URL in the database using async operations and error handling with Mongoose.']}], 'duration': 208.206, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ1019488.jpg', 'highlights': ['Implement URL shortener code logic using short ID package.', 'Set base URL from a config file.', "Validate URL using 'isValidURL' method to ensure it's a valid URI or URL.", 'Generate a code based on the Bitly website link for the long URL.', 'Check for the existence of the URL in the database using async operations and error handling with Mongoose.']}, {'end': 1652.893, 'segs': [{'end': 1260.963, 'src': 'embed', 'start': 1227.814, 'weight': 0, 'content': [{'end': 1230.975, 'text': 'And we want to find it by long URL.', 'start': 1227.814, 'duration': 3.161}, {'end': 1233.356, 'text': 'And this is the same as doing this.', 'start': 1231.335, 'duration': 2.021}, {'end': 1240.213, 'text': 'OK, now we want to see if there is a URL found.', 'start': 1235.37, 'duration': 4.843}, {'end': 1248.337, 'text': "So let's say if there is a URL, then we want to just return that or respond with that.", 'start': 1240.333, 'duration': 8.004}, {'end': 1252.739, 'text': 'So we can just do res dot Jason, which will give a 200 response.', 'start': 1248.397, 'duration': 4.342}, {'end': 1259.503, 'text': "And we'll send the URL, which will have all the database fields, the long, the short, the code and the date.", 'start': 1253.079, 'duration': 6.424}, {'end': 1260.963, 'text': 'All right.', 'start': 1260.623, 'duration': 0.34}], 'summary': 'The goal is to find a long url and return it with database fields like long, short, code, and date.', 'duration': 33.149, 'max_score': 1227.814, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ1227814.jpg'}, {'end': 1355.516, 'src': 'embed', 'start': 1325.094, 'weight': 4, 'content': [{'end': 1327.356, 'text': "So in here, we're going to have the long URL.", 'start': 1325.094, 'duration': 2.262}, {'end': 1328.577, 'text': 'We want that inserted.', 'start': 1327.476, 'duration': 1.101}, {'end': 1331.359, 'text': 'We also want the short URL that we just created.', 'start': 1328.737, 'duration': 2.622}, {'end': 1333.741, 'text': 'And we also want the URL code.', 'start': 1331.819, 'duration': 1.922}, {'end': 1336.483, 'text': 'And then remember, we also have the date.', 'start': 1334.701, 'duration': 1.782}, {'end': 1339.925, 'text': "So I'll just set that to whatever the date is.", 'start': 1336.503, 'duration': 3.422}, {'end': 1346.95, 'text': "OK, and then we need to save it because just saying new URL doesn't actually save it.", 'start': 1341.567, 'duration': 5.383}, {'end': 1349.532, 'text': 'It just creates the instance to save it.', 'start': 1346.971, 'duration': 2.561}, {'end': 1355.516, 'text': 'We need to call URL dot save, which returns a promise.', 'start': 1349.832, 'duration': 5.684}], 'summary': 'Creating a new url with long and short url, url code, and date, then saving it with url dot save.', 'duration': 30.422, 'max_score': 1325.094, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ1325094.jpg'}, {'end': 1521.956, 'src': 'embed', 'start': 1450.063, 'weight': 1, 'content': [{'end': 1453.565, 'text': "And then we're checking the base URL, making sure that's valid.", 'start': 1450.063, 'duration': 3.502}, {'end': 1457.726, 'text': "Then we're generating our URL code for the short URL.", 'start': 1454.185, 'duration': 3.541}, {'end': 1461.308, 'text': "We're checking the long URL to make sure that's valid.", 'start': 1458.467, 'duration': 2.841}, {'end': 1463.209, 'text': "This is what's sent in from the client.", 'start': 1461.348, 'duration': 1.861}, {'end': 1467.831, 'text': "Then we're looking to see if that URL is in there.", 'start': 1463.909, 'duration': 3.922}, {'end': 1474.634, 'text': "Like if there's a URL for google.com that's already in the database, then we're just going to return whatever that is, whatever's there.", 'start': 1467.851, 'duration': 6.783}, {'end': 1478.716, 'text': "Else, then we're going to construct the new short URL.", 'start': 1475.274, 'duration': 3.442}, {'end': 1489.562, 'text': "We're going to instantiate a new URL object with the long, short, the code, and the date.", 'start': 1479.437, 'duration': 10.125}, {'end': 1493.145, 'text': "We're going to save it to the database and then respond with it.", 'start': 1490.043, 'duration': 3.102}, {'end': 1503.189, 'text': "OK, down here, something goes wrong, we'll send a server error 500 if the if the URL is invalid, the long one, then we'll send this status.", 'start': 1494.245, 'duration': 8.944}, {'end': 1504.069, 'text': 'All right.', 'start': 1503.829, 'duration': 0.24}, {'end': 1505.27, 'text': "So that's what's going on here.", 'start': 1504.109, 'duration': 1.161}, {'end': 1513.073, 'text': 'So I guess, yeah, I guess we can go ahead and try this out now.', 'start': 1506.73, 'duration': 6.343}, {'end': 1517.735, 'text': 'Like I said, you can use whatever you want to to to make this post request.', 'start': 1513.373, 'duration': 4.362}, {'end': 1521.956, 'text': "I'm going to use something called Rest Client, which is a V.S.", 'start': 1517.835, 'duration': 4.121}], 'summary': 'Validating, generating, and saving short urls to the database for client requests.', 'duration': 71.893, 'max_score': 1450.063, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ1450063.jpg'}], 'start': 1227.814, 'title': 'Url shortening api', 'summary': 'Outlines the implementation of a url shortening api, covering the process of finding and returning a long url, constructing a short url, handling server errors and invalid long urls, and achieving successful shortened url creation.', 'chapters': [{'end': 1349.532, 'start': 1227.814, 'title': 'Url shortener endpoint implementation', 'summary': 'Outlines the implementation of a url shortener endpoint, including the process of finding and returning a long url, constructing a short url, and inserting the url into the database, with a focus on the logic and steps involved in each action.', 'duration': 121.718, 'highlights': ['The implementation involves finding and returning a long URL if it is found, and responding with a 200 status code along with the database fields (long, short, code, and date).', 'In the absence of a URL found, the process includes constructing a short URL using a base URL and the URL code, generated using a specific method, to create a new URL to insert into the database.', 'The insertion of the new URL into the database involves providing the long URL, the newly created short URL, the URL code, and the date, followed by the necessity to explicitly save the new URL instance.']}, {'end': 1652.893, 'start': 1349.832, 'title': 'Url shortening api implementation', 'summary': 'Details the implementation of a url shortening api, including handling server errors and invalid long urls, with an example of making a post request and receiving a response, achieving a successful shortened url creation.', 'duration': 303.061, 'highlights': ['The chapter details the implementation of a URL shortening API, including handling server errors and invalid long URLs The chapter provides a detailed explanation of implementing a URL shortening API, covering aspects such as handling server errors and invalid long URLs.', 'Example of making a post request and receiving a response The transcript includes an example of making a post request using Rest Client and receiving a response from the server.', 'Achieving a successful shortened URL creation The example demonstrates the successful creation of a shortened URL, with the response containing the ID, long URL, short URL, code, and date and time.']}], 'duration': 425.079, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ1227814.jpg', 'highlights': ['The implementation involves finding and returning a long URL if it is found, and responding with a 200 status code along with the database fields (long, short, code, and date).', 'The chapter details the implementation of a URL shortening API, including handling server errors and invalid long URLs.', 'In the absence of a URL found, the process includes constructing a short URL using a base URL and the URL code, generated using a specific method, to create a new URL to insert into the database.', 'Example of making a post request and receiving a response The transcript includes an example of making a post request using Rest Client and receiving a response from the server.', 'The insertion of the new URL into the database involves providing the long URL, the newly created short URL, the URL code, and the date, followed by the necessity to explicitly save the new URL instance.', 'Achieving a successful shortened URL creation The example demonstrates the successful creation of a shortened URL, with the response containing the ID, long URL, short URL, code, and date and time.']}, {'end': 2044.889, 'segs': [{'end': 1761.469, 'src': 'embed', 'start': 1652.953, 'weight': 0, 'content': [{'end': 1657.175, 'text': 'If we go to MongoDB or Atlas and we go to collections.', 'start': 1652.953, 'duration': 4.222}, {'end': 1660.301, 'text': 'You can see there it is.', 'start': 1659.301, 'duration': 1}, {'end': 1661.282, 'text': 'So it got stored.', 'start': 1660.361, 'duration': 0.921}, {'end': 1671.466, 'text': "Now this link is not going to work, right? If I go ahead and copy this and I paste this in, it's looking for this route.", 'start': 1661.362, 'duration': 10.104}, {'end': 1676.289, 'text': 'So what we need to do now is create another endpoint for the codes.', 'start': 1671.506, 'duration': 4.783}, {'end': 1679.55, 'text': "And that's going to go in the index.js route file.", 'start': 1676.809, 'duration': 2.741}, {'end': 1680.791, 'text': "So let's head over to that.", 'start': 1679.61, 'duration': 1.181}, {'end': 1684.092, 'text': 'We can go ahead and close that up.', 'start': 1681.831, 'duration': 2.261}, {'end': 1688.93, 'text': "Um, yeah, I guess, I guess we'll save that request.", 'start': 1686.447, 'duration': 2.483}, {'end': 1689.93, 'text': 'All right.', 'start': 1689.65, 'duration': 0.28}, {'end': 1692.973, 'text': 'So we can close up URL dot JS.', 'start': 1689.97, 'duration': 3.003}, {'end': 1698.057, 'text': "Now let's go into our routes folder and then index JS.", 'start': 1693.213, 'duration': 4.844}, {'end': 1699.559, 'text': "Cause that's where we're going to put this.", 'start': 1698.077, 'duration': 1.482}, {'end': 1702.121, 'text': 'So we need to bring in our model.', 'start': 1700.299, 'duration': 1.822}, {'end': 1709.173, 'text': 'And this is going to be pretty easy.', 'start': 1707.532, 'duration': 1.641}, {'end': 1714.257, 'text': 'So dot dot slash models slash URL.', 'start': 1710.575, 'duration': 3.682}, {'end': 1716.139, 'text': "And then let's create our route.", 'start': 1714.778, 'duration': 1.361}, {'end': 1722.684, 'text': "So let's say route.", 'start': 1716.279, 'duration': 6.405}, {'end': 1725.827, 'text': "So it's a get request.", 'start': 1724.446, 'duration': 1.381}, {'end': 1730.21, 'text': "And it's going to be to just slash and then whatever the code is.", 'start': 1726.027, 'duration': 4.183}, {'end': 1734.474, 'text': "And let's do description.", 'start': 1732.312, 'duration': 2.162}, {'end': 1745.964, 'text': "So the description we're going to redirect to the long or original URL.", 'start': 1736.696, 'duration': 9.268}, {'end': 1750.767, 'text': "OK, so it's going to be a get request, so we'll say router dot get.", 'start': 1747.024, 'duration': 3.743}, {'end': 1760.408, 'text': "And we're just going to say in here slash colon code, because obviously this is a parameter.", 'start': 1752.203, 'duration': 8.205}, {'end': 1761.469, 'text': 'This is a placeholder.', 'start': 1760.428, 'duration': 1.041}], 'summary': 'Creating a new endpoint for redirecting to original url in index.js route file.', 'duration': 108.516, 'max_score': 1652.953, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ1652953.jpg'}, {'end': 1872.635, 'src': 'embed', 'start': 1832.151, 'weight': 4, 'content': [{'end': 1836.634, 'text': "So we'll take that URL object, and we want the long URL property.", 'start': 1832.151, 'duration': 4.483}, {'end': 1839.436, 'text': "That's what we're redirecting to.", 'start': 1837.995, 'duration': 1.441}, {'end': 1846.902, 'text': "Else, then let's just return a res.status of 400.", 'start': 1840.257, 'duration': 6.645}, {'end': 1851.566, 'text': 'Actually, I guess we could do a 404 and say .json and say no URL found.', 'start': 1846.902, 'duration': 4.664}, {'end': 1863.351, 'text': "And then in the catch here, we'll just do our console error and just log whatever is in error.", 'start': 1857.468, 'duration': 5.883}, {'end': 1868.013, 'text': "And then we'll do a res dot status 500.", 'start': 1863.791, 'duration': 4.222}, {'end': 1872.635, 'text': "And we'll just say server error.", 'start': 1868.013, 'duration': 4.622}], 'summary': 'Handling url redirection and error responses with status codes 400, 404, and 500.', 'duration': 40.484, 'max_score': 1832.151, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ1832151.jpg'}, {'end': 1930.941, 'src': 'heatmap', 'start': 1895.422, 'weight': 5, 'content': [{'end': 1900.607, 'text': 'If you want to do a standard redirect or I mean, you can handle it in a different way if you want to.', 'start': 1895.422, 'duration': 5.185}, {'end': 1902.088, 'text': 'But I think that this is fine.', 'start': 1900.687, 'duration': 1.401}, {'end': 1912.217, 'text': "So now let's let's once again copy the short URL here and let's open up a new tab and let's go to it.", 'start': 1902.829, 'duration': 9.388}, {'end': 1913.718, 'text': 'And there we go.', 'start': 1913.158, 'duration': 0.56}, {'end': 1915.64, 'text': 'So our service is working.', 'start': 1914.319, 'duration': 1.321}, {'end': 1918.283, 'text': 'We can now generate short URLs.', 'start': 1916.401, 'duration': 1.882}, {'end': 1919.938, 'text': 'and they work.', 'start': 1919.298, 'duration': 0.64}, {'end': 1928.541, 'text': "And just to kind of try it one more time, let's see, let's get a different URL.", 'start': 1921.059, 'duration': 7.482}, {'end': 1930.941, 'text': "We'll grab this right here.", 'start': 1928.561, 'duration': 2.38}], 'summary': 'A service for generating short urls is now functional, allowing for successful redirection and usability.', 'duration': 35.519, 'max_score': 1895.422, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ1895422.jpg'}], 'start': 1652.953, 'title': 'Creating new endpoints and a url shortening service', 'summary': 'Covers creating a new endpoint for storing data in mongodb or atlas, including code implementation and model integration, and explains the process of creating a url shortening service with successful testing and functionality for generating and redirecting short urls.', 'chapters': [{'end': 1722.684, 'start': 1652.953, 'title': 'Creating a new endpoint for storing data', 'summary': 'Discusses creating a new endpoint for storing data in mongodb or atlas, including the need to create a new endpoint for codes in the index.js route file and bringing in the model for the route.', 'duration': 69.731, 'highlights': ['Creating a new endpoint for storing data in MongoDB or Atlas.', 'The need to create a new endpoint for codes in the index.js route file.', 'Bringing in the model for the route.']}, {'end': 2044.889, 'start': 1724.446, 'title': 'Creating a url shortening service', 'summary': 'Explains the process of creating a url shortening service using a get request to redirect to the original url, handling different http status codes, and testing the functionality, resulting in the successful creation of a service for generating and redirecting short urls.', 'duration': 320.443, 'highlights': ['The chapter explains the process of creating a URL shortening service using a get request to redirect to the original URL. Use of get request to redirect to original URL, creation of a URL shortening service.', 'Handling different HTTP status codes, including 400 and 404, for different scenarios such as no URL found and server error. Handling of HTTP status codes, including 400 and 404, for different scenarios.', 'Testing the functionality and verifying the successful creation of a service for generating and redirecting short URLs. Testing the functionality, successful creation of a service for generating and redirecting short URLs.']}], 'duration': 391.936, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/Z57566JBaZQ/pics/Z57566JBaZQ1652953.jpg', 'highlights': ['Creating a new endpoint for storing data in MongoDB or Atlas.', 'The need to create a new endpoint for codes in the index.js route file.', 'Bringing in the model for the route.', 'The chapter explains the process of creating a URL shortening service using a get request to redirect to the original URL.', 'Handling different HTTP status codes, including 400 and 404, for different scenarios such as no URL found and server error.', 'Testing the functionality and verifying the successful creation of a service for generating and redirecting short URLs.']}], 'highlights': ['Creating a new endpoint for storing data in MongoDB or Atlas.', 'The chapter explains the process of creating a URL shortening service using a get request to redirect to the original URL.', 'The chapter details the implementation of a URL shortening API, including handling server errors and invalid long URLs.', 'The chapter discusses building a URL shortener service using Node.js, Express, and MongoDB.', 'Setting up a basic Express server and connecting to a MongoDB database.', 'The process involves bringing in a valid URL method from the valid URL package, a short id, config, and the url model from the models directory.', "The chapter explains the process of creating a post request endpoint '/API/URL/shorten' to create a short URL.", 'The chapter details the creation of route signatures for the short URLs.', 'The implementation involves finding and returning a long URL if it is found, and responding with a 200 status code along with the database fields (long, short, code, and date).', 'The insertion of the new URL into the database involves providing the long URL, the newly created short URL, the URL code, and the date, followed by the necessity to explicitly save the new URL instance.', 'Achieving a successful shortened URL creation The example demonstrates the successful creation of a shortened URL, with the response containing the ID, long URL, short URL, code, and date and time.', 'Implement URL shortener code logic using short ID package.', 'Set base URL from a config file.', "Validate URL using 'isValidURL' method to ensure it's a valid URI or URL.", 'Generate a code based on the Bitly website link for the long URL.', 'Check for the existence of the URL in the database using async operations and error handling with Mongoose.', 'Defining two routes, index.js and url.js, for creating short URLs and redirecting to long URLs.', 'Setting up a Mongoose model for URL by exporting the model using mongoose.model and passing in the schema.', 'Creating a Mongoose model for URL schema, including defining fields like URL code, long URL, short URL, and date.', 'The need to create a new endpoint for codes in the index.js route file.', 'Handling different HTTP status codes, including 400 and 404, for different scenarios such as no URL found and server error.', 'Testing the functionality and verifying the successful creation of a service for generating and redirecting short URLs.']}