using System; using EmbedIO.Actions; using EmbedIO.Utilities; using Swan; namespace EmbedIO { partial class WebModuleContainerExtensions { /// /// Creates an instance of and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The base route of the module. /// The HTTP verb that will be served by . /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer WithAction(this TContainer @this, string baseRoute, HttpVerbs verb, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer { @this.Modules.Add(new ActionModule(baseRoute, verb, handler)); return @this; } /// /// Creates an instance of with a base URL path of "/" /// and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The HTTP verb that will be served by . /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer WithAction(this TContainer @this, HttpVerbs verb, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, UrlPath.Root, verb, handler); /// /// Creates an instance of that intercepts all requests /// under the specified and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The base route of the module. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnAny(this TContainer @this, string baseRoute, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, baseRoute, HttpVerbs.Any, handler); /// /// Creates an instance of that intercepts all requests /// and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnAny(this TContainer @this, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, UrlPath.Root, HttpVerbs.Any, handler); /// /// Creates an instance of that intercepts all DELETErequests /// under the specified and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The base route of the module. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnDelete(this TContainer @this, string baseRoute, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, baseRoute, HttpVerbs.Delete, handler); /// /// Creates an instance of that intercepts all DELETErequests /// and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnDelete(this TContainer @this, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, UrlPath.Root, HttpVerbs.Delete, handler); /// /// Creates an instance of that intercepts all GETrequests /// under the specified and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The base route of the module. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnGet(this TContainer @this, string baseRoute, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, baseRoute, HttpVerbs.Get, handler); /// /// Creates an instance of that intercepts all GETrequests /// and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnGet(this TContainer @this, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, UrlPath.Root, HttpVerbs.Get, handler); /// /// Creates an instance of that intercepts all HEADrequests /// under the specified and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The base route of the module. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnHead(this TContainer @this, string baseRoute, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, baseRoute, HttpVerbs.Head, handler); /// /// Creates an instance of that intercepts all HEADrequests /// and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnHead(this TContainer @this, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, UrlPath.Root, HttpVerbs.Head, handler); /// /// Creates an instance of that intercepts all OPTIONSrequests /// under the specified and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The base route of the module. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnOptions(this TContainer @this, string baseRoute, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, baseRoute, HttpVerbs.Options, handler); /// /// Creates an instance of that intercepts all OPTIONSrequests /// and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnOptions(this TContainer @this, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, UrlPath.Root, HttpVerbs.Options, handler); /// /// Creates an instance of that intercepts all PATCHrequests /// under the specified and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The base route of the module. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnPatch(this TContainer @this, string baseRoute, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, baseRoute, HttpVerbs.Patch, handler); /// /// Creates an instance of that intercepts all PATCHrequests /// and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnPatch(this TContainer @this, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, UrlPath.Root, HttpVerbs.Patch, handler); /// /// Creates an instance of that intercepts all POSTrequests /// under the specified and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The base route of the module. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnPost(this TContainer @this, string baseRoute, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, baseRoute, HttpVerbs.Post, handler); /// /// Creates an instance of that intercepts all POSTrequests /// and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnPost(this TContainer @this, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, UrlPath.Root, HttpVerbs.Post, handler); /// /// Creates an instance of that intercepts all PUTrequests /// under the specified and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The base route of the module. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnPut(this TContainer @this, string baseRoute, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, baseRoute, HttpVerbs.Put, handler); /// /// Creates an instance of that intercepts all PUTrequests /// and adds it to a module container. /// /// The type of the module container. /// The on which this method is called. /// The callback used to handle requests. /// with a added. /// is . /// /// /// public static TContainer OnPut(this TContainer @this, RequestHandlerCallback handler) where TContainer : class, IWebModuleContainer => WithAction(@this, UrlPath.Root, HttpVerbs.Put, handler); } }