public function register($method, $path, $action, $filter = null)
    {
        // Add leading slash if not present
        if (strncmp($path, '/', 1) !== 0) {
            $path = '/' . $path;
        }

        // Add API base url to the path
        $path = $this->app->config('url.root') . $path;

        // Create arrays
        $params = [];
        $matches = [];
        $method = strtolower($method);

        // Replace placeholders
        if (preg_match_all('/\{([\w-\.]+)\}/i', $path, $matches)) {
            $params = end($matches);
        }
        $pattern = preg_replace(
            ['/(\{[\w-\.]+\})/i', '/\\//'],
            ['([\w-\.]+)', '\\/'],
            $path
        );

        // Store in the routes array
        return $this->routes[$method][$path] = [
            'path' => $path,
            'pattern' => '/^' . $pattern . '\\/?$/i',
            'class' => $action[0],
            'method' => $action[1],
            'params' => $params,
            'filter' => $filter
        ];
    }