<commit_before>/**
    Any type that conforms to this protocol
    can be passed as a requirement to Vapor's
    type-safe route calls.
*/
public protocol StringInitializable {
    init?(from string: String) throws
}

///Allow the Int type to be a type-safe routing parameter
extension Int: StringInitializable {
    public init?(from string: String) throws {
        guard let int = Int(string) else {
            return nil
        }

        self = int
    }
}

///Allow the String type to be a type-safe routing parameter
extension String: StringInitializable {
    public init?(from string: String) throws {
        self = string
    }
}

extension Application {

    public final func any(path: String, handler: Route.Handler) {
        self.get(path, handler: handler)
        self.post(path, handler: handler)
        self.put(path, handler: handler)
        self.patch(path, handler: handler)
        self.delete(path, handler: handler)
    }

    /**
        Creates standard Create, Read, Update, Delete routes
        using the Handlers from a supplied `ResourceController`.

        Note: You are responsible for pluralizing your endpoints.
    */
    public final func resource<Resource: ResourceController>(_ path: String, makeControllerWith controllerFactory: () -> Resource) {
        //GET /entities
        self.get(path) { request in
            return try controllerFactory().index(request)
        }

        //POST /entities
        self.post(path) { request in
            return try controllerFactory().index(request)
        }

        //GET /entities/:id
        self.get(path, Resource.Item.self) { request, item in
            return try controllerFactory().show(request, item: item)
        }

        //PUT /entities/:id
        self.put(path, Resource.Item.self) { request, item in
            return try controllerFactory().update(request, item: item)
        }

        //DELETE /intities/:id
        self.delete(path, Resource.Item.self) { request, item in
            return try controllerFactory().destroy(request, item: item)
        }

    }

    public final func resource<Resource: ResourceController where Resource: ApplicationInitializable>(_ path: String, controller: Resource.Type) {
        resource(path) {
            return controller.init(application: self)
        }
    }

    public final func resource<Resource: ResourceController where Resource: DefaultInitializable>(_ path: String, controller: Resource.Type) {
        resource(path) {
            return controller.init()
        }
    }

    public final func add(_ method: Request.Method, path: String, handler: Route.Handler) {
        //Convert Route.Handler to Request.Handler
        var responder: Responder = Request.Handler { request in
            return try handler(request).makeResponse()
        }

        //Apply any scoped middlewares
        for middleware in self.scopedMiddleware {
            responder = middleware.chain(to: responder)
        }

        //Store the route for registering with Router later
        let host = scopedHost ?? "*"

        //Apply any scoped prefix
        var path = path<commit_msg>Adds a headerdoc for route add<commit_after>/**
    Any type that conforms to this protocol
    can be passed as a requirement to Vapor's
    type-safe route calls.
*/
public protocol StringInitializable {
    init?(from string: String) throws
}

///Allow the Int type to be a type-safe routing parameter
extension Int: StringInitializable {
    public init?(from string: String) throws {
        guard let int = Int(string) else {
            return nil
        }

        self = int
    }
}

///Allow the String type to be a type-safe routing parameter
extension String: StringInitializable {
    public init?(from string: String) throws {
        self = string
    }
}

extension Application {

    public final func any(path: String, handler: Route.Handler) {
        self.get(path, handler: handler)
        self.post(path, handler: handler)
        self.put(path, handler: handler)
        self.patch(path, handler: handler)
        self.delete(path, handler: handler)
    }

    /**
        Creates standard Create, Read, Update, Delete routes
        using the Handlers from a supplied `ResourceController`.

        Note: You are responsible for pluralizing your endpoints.
    */
    public final func resource<Resource: ResourceController>(_ path: String, makeControllerWith controllerFactory: () -> Resource) {
        //GET /entities
        self.get(path) { request in
            return try controllerFactory().index(request)
        }

        //POST /entities
        self.post(path) { request in
            return try controllerFactory().index(request)
        }

        //GET /entities/:id
        self.get(path, Resource.Item.self) { request, item in
            return try controllerFactory().show(request, item: item)
        }

        //PUT /entities/:id
        self.put(path, Resource.Item.self) { request, item in
            return try controllerFactory().update(request, item: item)
        }

        //DELETE /intities/:id
        self.delete(path, Resource.Item.self) { request, item in
            return try controllerFactory().destroy(request, item: item)
        }

    }

    public final func resource<Resource: ResourceController where Resource: ApplicationInitializable>(_ path: String, controller: Resource.Type) {
        resource(path) {
            return controller.init(application: self)
        }
    }

    public final func resource<Resource: ResourceController where Resource: DefaultInitializable>(_ path: String, controller: Resource.Type) {
        resource(path) {
            return controller.init()
        }
    }

    /**
     Adds a route handler for an HTTP request using a given HTTP verb at a given
     path. The provided handler will be ran whenever the path is requested with 
     the given method.
     
     - parameter    method:     The `Request.Method` that the handler should be executed for.
     - parameter    path:       The HTTP path that handler can run at.
     - parameter    handler:    The code to process the request with.
    */
    public final func add(_ method: Request.Method, path: String, handler: Route.Handler) {
        //Convert Route.Handler to Request.Handler
        var responder: Responder = Request.Handler { request in
            return try handler(request).makeResponse()
        }

        //Apply any scoped middlewares
        for middleware in self.scopedMiddleware {
            responder = middleware.chain(to: responder)
        }

        //Store the route for registering with Router later
        let host = scopedHost ?? "*"

        //Apply any scoped prefix
        var path = path
{'fraction_non_alphanumeric': 0.08704033214709371, 'fraction_numerical': 0.0, 'mean_word_length': 2.3341571922886803, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2484832', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1681, 'n_words': 594}