Public static bool ValidateDestination(string? destination, out string validationResults) ValidationResults.Add("path", pathValidationResults) ValidationResults.Add("destination", destinationValidationResults) Var isDestinationValid = ValidateDestination( Public static bool Validate(this ShortUrl shortUrl, out IDictionary validationResults) Private static readonly Regex PathRegex = new Regex( Create the Data Layerįirst, open a terminal and run the following commands to create a folder, navigate into it, and create a solution file using the. Lastly, since these two applications will interact with the same data store and perform some of the same functionality, you'll create a class library for shared functionality for the CRUD operations and validation. However, you could use any data store you'd like in your own implementation. I chose Redis for this application because it works well as a key-value database, it is well-supported, and there's a great. The key of each shortened URL will be the unique path that will be used to browse to the URL, and the value will be the destination URL. The CLI application will store the collection of shortened URLs in a Redis database. While you'll build the CRUD functionality in a CLI app, you could build the same app as a website or API using ASP.NET Core, or client app using WPF, WinForms, Avalonia, MAUI, etc. While these libraries are still in preview, they work well and provide common functionality needed to build CLI applications. The CLI application will take advantage of the open-source System.CommandLine libraries. You'll build the Forwarder App using an ASP.NET Core Minimal API, and you'll also build a command-line interface (CLI) application to provide the CRUD functionality. The Forwarder App then sends back an HTTP response with status code 307 Temporary Redirect pointing towards the destination URL (3). The forwarder app will look at the path of the request and look up the destination URL in the same Redis Database and return it to the Forwarder App (2). When the user clicks on the shortened URL, the web browser sends an HTTP GET request to that URL which is received by the Forwarder App (1). Let's say a mobile user received an SMS with a shortened URL. The two applications will work together as shown in the diagram above.Īn administrator can use the CLI CRUD ( Create Read Update Delete) application (1) to manage the shortened URL data in a Redis Database (2). While these two parts could live within a single application, you will build separate applications for URL management and for URL forwarding. There are two parts to URL shorteners: forwarding the shortened URLs to the destination URL and the management of the shortened URLs.
2 Comments
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |