Welcome Guest, Not a member yet? Register   Sign In
How should I implement x-api-key and api rate limit in CodeIgniter 4 ?
#1

Hi

I have a bunch of ResourceController controllers which build a simple api rest
Then I have a filter with this before code (which is assigned only to api routes)

Code:
Services::response()->setHeader('Access-Control-Allow-Origin',$base_url);
        if (strtolower($request->getMethod()) === 'options') {
            return Services::response()
                ->setHeader("Access-Control-Allow-Headers",
                    [
                        'X-API-KEY',
                        'Origin',
                        'X-Requested-With',
                        'Content-Type',
                        'Accept',
                        'Access-Control-Request-Method',
                        'Authorization',
                    ])
                ->setHeader("Access-Control-Allow-Methods", ['GET', 'POST', 'OPTIONS', 'PUT', 'DELETE']);
        }

I have to implement for all the api controllers, the following

1. X-API-KEY
2. API rate limit (fixed for all routes, very basic)

Which would be the best way to implement each? Create a new filter for each feature?
Does anyone have any useful links to share to get started?

Thanks a lot
Reply


Messages In This Thread
How should I implement x-api-key and api rate limit in CodeIgniter 4 ? - by kabeza - 05-24-2022, 05:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB