From the course: Building and Securing RESTful APIs in ASP.NET Core
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Rewrite resource HREFs - ASP.NET Core Tutorial
From the course: Building and Securing RESTful APIs in ASP.NET Core
Rewrite resource HREFs
- [Instructor] We've used a result filter to automatically add absolute link urls to our API responses, but the href's on the resources themselves need the same treatment. Right now, in the resource model, the base class includes a property called Href. Let's replace this with a link property called Self. Now we can set this property in controller code. For example, in the root controller, instead of Href, now I can say Self equals Link.To, say name of Getroot. This also works in other places, like in the Automapper profile that we created earlier. In mapping profile we can finally get rid of this ToDo and say ForMember, the destination, Self, and we will map that from, we'll say Link.To, the route name will be name of Controllers.RoomsController.GetRoomById. And we also need to pass route values here, that'll be a new anonymous object, roomId equals src.Id. And we can get rid of this comment. The link rewriting filter will handle this new Self property with no problems. However, we…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.