Resources
Resources provide an unified way to load and access binary data used by handlersto achieve their functionality. For example, theDownload handlerserves a single file on request - where the content of the file originates fromis not important for the handler to achieve it’s functionality.
var resource = Resource.FromFile("/var/www/downloads/myvideo.mp4");// or FromString, FromAssembly, ...var download = Download.From(resource);await Host.Create() .Handler(download) .RunAsync();
By implementing theIResource
interface, a custom data source can be used toprovide resources, for example a database or a cloud blob storage.
Resource Trees
Similar to the resources, resource trees provide an abstraction for a directorystructure that can be consumed by handlers such as theDirectory Browsingor theSingle Page Application.
var tree = ResourceTree.FromDirectory("/var/www/downloads/");// or FromAssembly, ...var listing = Listing.From(tree);await Host.Create() .Handler(listing) .RunAsync();
Virtual trees allow to combine different sources of resources into an unified tree:
var tree = VirtualTree.Create() .Add("index.html", Resource.FromFile(...)) .Add("config.js", Resource.FromAssembly(...)) .Add("dist", ResourceTree.FromDirectory(...));var app = SinglePageApplication.From(tree);