{"id":413,"date":"2025-10-27T11:54:36","date_gmt":"2025-10-27T11:54:36","guid":{"rendered":"https:\/\/naveedshahzad.net\/blog\/?p=413"},"modified":"2025-10-27T12:12:49","modified_gmt":"2025-10-27T12:12:49","slug":"build-restful-api-codeigniter4-jwt-logging","status":"publish","type":"post","link":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/","title":{"rendered":"Designing a RESTful API in CodeIgniter 4 with Authentication, Rate Limiting, and Logging"},"content":{"rendered":"<p>In modern web development, APIs form the backbone of digital ecosystems. Whether you\u2019re powering a mobile app, a front-end dashboard, or integrating with third-party systems, a well-structured RESTful API is essential.<\/p>\n<p><strong>CodeIgniter 4 (CI4)<\/strong>, being lightweight, fast, and modular, provides an excellent framework for building secure and scalable APIs. In this article, we\u2019ll go beyond the basics and explore how to design a robust RESTful API in CI4 \u2014 complete with <strong>JWT authentication<\/strong>, <strong>rate limiting<\/strong>, and <strong>activity logging<\/strong>.<\/p>\n<p>This guide is for developers who already know the fundamentals of CodeIgniter and want to implement <strong>production-grade API practices.<\/strong><\/p>\n<h3>1. Setting Up the Project Structure<\/h3>\n<p>Start with a clean CodeIgniter 4 installation:<br \/>\n<code><br \/>\ncomposer create-project codeigniter4\/appstarter ci4-api<br \/>\ncd ci4-api<br \/>\nphp spark serve<br \/>\n<\/code><br \/>\nCI4\u2019s directory structure is ideal for REST API organization. However, to make things modular and scalable, it\u2019s best to follow this structure:<br \/>\n<code><br \/>\napp\/<br \/>\n\u251c\u2500\u2500 Controllers\/<br \/>\n\u2502    \u251c\u2500\u2500 Api\/<br \/>\n\u2502    \u2502    \u2514\u2500\u2500 V1\/<br \/>\n\u2502    \u2502         \u2514\u2500\u2500 Users.php<br \/>\n\u251c\u2500\u2500 Models\/<br \/>\n\u2502    \u2514\u2500\u2500 UserModel.php<br \/>\n\u251c\u2500\u2500 Filters\/<br \/>\n\u2502    \u251c\u2500\u2500 AuthFilter.php<br \/>\n\u2502    \u251c\u2500\u2500 RateLimitFilter.php<br \/>\n\u251c\u2500\u2500 Helpers\/<br \/>\n\u2502    \u2514\u2500\u2500 jwt_helper.php<br \/>\n\u251c\u2500\u2500 Libraries\/<br \/>\n\u2502    \u2514\u2500\u2500 ActivityLogger.php<br \/>\n<\/code><\/p>\n<p>This modular separation allows you to extend API versions easily, such as \/api\/v1\/ and \/api\/v2\/ later.<\/p>\n<h3>2. Creating RESTful Routes<\/h3>\n<p>Define your API routes inside app\/Config\/Routes.php:<br \/>\n<code><br \/>\n$routes-&gt;group('api\/v1', ['namespace' =&gt; 'App\\Controllers\\Api\\V1'], static function ($routes) {<br \/>\n$routes-&gt;post('login', 'Auth::login');<br \/>\n$routes-&gt;post('register', 'Auth::register');<br \/>\n$routes-&gt;get('users', 'Users::index', ['filter' =&gt; 'authfilter']);<br \/>\n$routes-&gt;get('users\/(:num)', 'Users::show\/$1', ['filter' =&gt; 'authfilter']);<br \/>\n});<br \/>\n<\/code><\/p>\n<p>We\u2019re defining a versioned API group (api\/v1) to future-proof the design.<br \/>\nNotice the use of authfilter \u2014 this will handle JWT authentication for protected routes.<\/p>\n<h3>3. Building the User Controller<\/h3>\n<p>Let\u2019s create our first controller at app\/Controllers\/Api\/V1\/Users.php:<\/p>\n<pre>namespace App\\Controllers\\Api\\V1;\r\n<code>\r\nuse App\\Controllers\\BaseController;\r\nuse App\\Models\\UserModel;\r\n\r\nclass Users extends BaseController\r\n{\r\nprotected $userModel;\r\n\r\npublic function __construct()\r\n{\r\n$this-&gt;userModel = new UserModel();\r\n}\r\n\r\npublic function index()\r\n{\r\n$users = $this-&gt;userModel-&gt;findAll();\r\nreturn $this-&gt;response-&gt;setJSON(['status' =&gt; 'success', 'data' =&gt; $users]);\r\n}\r\n\r\npublic function show($id)\r\n{\r\n$user = $this-&gt;userModel-&gt;find($id);\r\nif (!$user) {\r\nreturn $this-&gt;response-&gt;setJSON(['status' =&gt; 'error', 'message' =&gt; 'User not found'])-&gt;setStatusCode(404);\r\n}\r\nreturn $this-&gt;response-&gt;setJSON(['status' =&gt; 'success', 'data' =&gt; $user]);\r\n}\r\n}\r\n<\/code><\/pre>\n<p>This simple REST controller lists and retrieves users \u2014 a good foundation before we layer in authentication and security.<\/p>\n<h3>4. Implementing JWT Authentication<\/h3>\n<p>JWT (JSON Web Token) is ideal for stateless authentication.<br \/>\nLet\u2019s create a helper file at app\/Helpers\/jwt_helper.php:<\/p>\n<pre><code>\r\nuse Firebase\\JWT\\JWT;\r\nuse Firebase\\JWT\\Key;\r\n\r\nfunction generate_jwt($payload)\r\n{\r\n    $key = getenv('JWT_SECRET');\r\n    $payload['iat'] = time();\r\n    $payload['exp'] = time() + 3600; \/\/ 1 hour\r\n    return JWT::encode($payload, $key, 'HS256');\r\n}\r\n\r\nfunction verify_jwt($token)\r\n{\r\n    try {\r\n        $key = getenv('JWT_SECRET');\r\n        return JWT::decode($token, new Key($key, 'HS256'));\r\n    } catch (Exception $e) {\r\n        return null;\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>Now, add your secret key to .env:<\/p>\n<pre><code>\r\nJWT_SECRET = \"YOUR_SUPER_SECRET_KEY\"\r\n<\/code><\/pre>\n<p>Finally, create the AuthFilter in app\/Filters\/AuthFilter.php<\/p>\n<pre><code>\r\nnamespace App\\Filters;\r\n\r\nuse CodeIgniter\\HTTP\\RequestInterface;\r\nuse CodeIgniter\\HTTP\\ResponseInterface;\r\nuse CodeIgniter\\Filters\\FilterInterface;\r\n\r\nclass AuthFilter implements FilterInterface\r\n{\r\n    public function before(RequestInterface $request, $arguments = null)\r\n    {\r\n        $authHeader = $request-&gt;getHeaderLine('Authorization');\r\n        if (!$authHeader || !str_starts_with($authHeader, 'Bearer ')) {\r\n            return Services::response()-&gt;setJSON(['message' =&gt; 'Unauthorized'])-&gt;setStatusCode(401);\r\n        }\r\n\r\n        $token = substr($authHeader, 7);\r\n        $decoded = verify_jwt($token);\r\n        if (!$decoded) {\r\n            return Services::response()-&gt;setJSON(['message' =&gt; 'Invalid or expired token'])-&gt;setStatusCode(401);\r\n        }\r\n\r\n        $request-&gt;user = $decoded;\r\n    }\r\n\r\n    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)\r\n    {\r\n        \/\/ nothing here\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>Add this filter in app\/Config\/Filters.php:<\/p>\n<pre><code>\r\npublic array $aliases = [\r\n    'authfilter' =&gt; \\App\\Filters\\AuthFilter::class,\r\n];\r\n<\/code><\/pre>\n<p>Now your protected routes can only be accessed with a valid JWT.<\/p>\n<h3>5. Adding Rate Limiting<\/h3>\n<p>To prevent abuse and DoS attacks, let\u2019s implement rate limiting.<\/p>\n<p>Create app\/Filters\/RateLimitFilter.php:<\/p>\n<pre><code>\r\nnamespace App\\Filters;\r\n\r\nuse CodeIgniter\\Filters\\FilterInterface;\r\nuse CodeIgniter\\HTTP\\RequestInterface;\r\nuse CodeIgniter\\HTTP\\ResponseInterface;\r\nuse Config\\Services;\r\n\r\nclass RateLimitFilter implements FilterInterface\r\n{\r\n    private $maxRequests = 100;\r\n    private $window = 3600; \/\/ 1 hour\r\n\r\n    public function before(RequestInterface $request, $arguments = null)\r\n    {\r\n        $ip = $request-&gt;getIPAddress();\r\n        $cache = cache(\"ratelimit_$ip\") ?? ['count' =&gt; 0, 'time' =&gt; time()];\r\n\r\n        if (time() - $cache['time'] &gt; $this-&gt;window) {\r\n            $cache = ['count' =&gt; 1, 'time' =&gt; time()];\r\n        } else {\r\n            $cache['count']++;\r\n        }\r\n\r\n        cache()-&gt;save(\"ratelimit_$ip\", $cache, $this-&gt;window);\r\n\r\n        if ($cache['count'] &gt; $this-&gt;maxRequests) {\r\n            return Services::response()\r\n                -&gt;setJSON(['error' =&gt; 'Too many requests'])\r\n                -&gt;setStatusCode(429);\r\n        }\r\n    }\r\n\r\n    public function after(RequestInterface $request, ResponseInterface $response, $arguments = null) {}\r\n}\r\n<\/code><\/pre>\n<p>Then enable this filter in routes where appropriate:<\/p>\n<pre><code>\r\n$routes-&gt;get('users', 'Users::index', ['filter' =&gt; 'authfilter, ratelimit']);\r\n<\/code><\/pre>\n<p>This way, each IP is restricted to 100 requests per hour.<\/p>\n<h3>6. Logging API Activity<\/h3>\n<p>Logging is critical for debugging and analytics.<\/p>\n<p>Create a simple logger class at app\/Libraries\/ActivityLogger.php:<\/p>\n<pre><code>\r\nnamespace App\\Libraries;\r\n\r\nclass ActivityLogger\r\n{\r\n    public static function log($action, $details)\r\n    {\r\n        $data = [\r\n            'action' =&gt; $action,\r\n            'details' =&gt; json_encode($details),\r\n            'ip' =&gt; $_SERVER['REMOTE_ADDR'],\r\n            'created_at' =&gt; date('Y-m-d H:i:s'),\r\n        ];\r\n\r\n        file_put_contents(WRITEPATH . 'logs\/api_activity.log', json_encode($data) . PHP_EOL, FILE_APPEND);\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>Use it in your controller:<\/p>\n<pre><code>\r\nuse App\\Libraries\\ActivityLogger;\r\n\r\npublic function index()\r\n{\r\n    ActivityLogger::log('User Fetch', ['endpoint' =&gt; 'users']);\r\n    $users = $this-&gt;userModel-&gt;findAll();\r\n    return $this-&gt;response-&gt;setJSON(['status' =&gt; 'success', 'data' =&gt; $users]);\r\n}\r\n<\/code><\/pre>\n<p>You\u2019ll now have a detailed record of API actions for analysis and debugging.<\/p>\n<h3>7. Testing the API<\/h3>\n<p>Use <strong>Postman<\/strong> or <strong>cURL<\/strong> to test:<\/p>\n<ol>\n<li>Login (POST) \u2013 \/api\/v1\/login<\/li>\n<li>Receive JWT token<\/li>\n<li>Send GET request to \/api\/v1\/users with header:<br \/>\nAuthorization: Bearer your_jwt_token_here<\/li>\n<\/ol>\n<p>You should receive a secure JSON response.<\/p>\n<h3>8. Security Best Practices<\/h3>\n<p>To make your API production-ready:<\/p>\n<ul>\n<li>Always use <strong>HTTPS<\/strong>.<\/li>\n<li>Keep JWT secrets private and rotate keys periodically.<\/li>\n<li>Add <strong>CORS headers<\/strong> for controlled front-end access.<\/li>\n<li>Use pagination to avoid heavy data loads.<\/li>\n<li>Store logs securely and consider using a database for structured analytics.<\/li>\n<\/ul>\n<h3>Conclusion<\/h3>\n<p>Building a RESTful API in CodeIgniter 4 goes far beyond CRUD endpoints.<br \/>\nBy implementing JWT authentication, rate limiting, and activity logging, you can deliver a secure, scalable, and production-grade API that meets modern standards.<\/p>\n<p>This modular architecture allows future expansion \u2014 for example, integrating with mobile apps, third-party systems, or React-based dashboards \u2014 while keeping your backend stable and secure.<\/p>\n<p>If you\u2019re a developer looking to master backend design, CodeIgniter 4 offers a clean, flexible, and powerful foundation for professional-grade APIs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In modern web development, APIs form the backbone of digital ecosystems. Whether you\u2019re powering a mobile app, a front-end dashboard, or integrating with third-party systems, a well-structured RESTful API is essential. CodeIgniter 4 (CI4), being lightweight, fast, and modular, provides an excellent framework for building secure and scalable APIs. In this article, we\u2019ll go beyond [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":428,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-413","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-custom-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.7.1 (Yoast SEO v25.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Build a RESTful API in CodeIgniter 4 with JWT &amp; Logging<\/title>\n<meta name=\"description\" content=\"Learn to build a secure RESTful API in CodeIgniter 4 with JWT authentication, rate limiting, and logging using modern best practices.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Designing a RESTful API in CodeIgniter 4 with Authentication, Rate Limiting, and Logging\" \/>\n<meta property=\"og:description\" content=\"Learn to build a secure RESTful API in CodeIgniter 4 with JWT authentication, rate limiting, and logging using modern best practices.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/\" \/>\n<meta property=\"og:site_name\" content=\"Blogs - Naveed Shahzad\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/naveed.shahzad.35728\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/naveed.shahzad.35728\" \/>\n<meta property=\"article:published_time\" content=\"2025-10-27T11:54:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-27T12:12:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/10\/ci4-rest-apis-v2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"naveedshahzad\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@NaveedS92080775\" \/>\n<meta name=\"twitter:site\" content=\"@NaveedS92080775\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"naveedshahzad\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/\"},\"author\":{\"name\":\"naveedshahzad\",\"@id\":\"https:\/\/naveedshahzad.net\/blog\/#\/schema\/person\/2a4d03da05dae472db9d17f993781b04\"},\"headline\":\"Designing a RESTful API in CodeIgniter 4 with Authentication, Rate Limiting, and Logging\",\"datePublished\":\"2025-10-27T11:54:36+00:00\",\"dateModified\":\"2025-10-27T12:12:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/\"},\"wordCount\":533,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/naveedshahzad.net\/blog\/#\/schema\/person\/2a4d03da05dae472db9d17f993781b04\"},\"image\":{\"@id\":\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/10\/ci4-rest-apis-v2.png\",\"articleSection\":[\"Custom Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/\",\"url\":\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/\",\"name\":\"Build a RESTful API in CodeIgniter 4 with JWT & Logging\",\"isPartOf\":{\"@id\":\"https:\/\/naveedshahzad.net\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/10\/ci4-rest-apis-v2.png\",\"datePublished\":\"2025-10-27T11:54:36+00:00\",\"dateModified\":\"2025-10-27T12:12:49+00:00\",\"description\":\"Learn to build a secure RESTful API in CodeIgniter 4 with JWT authentication, rate limiting, and logging using modern best practices.\",\"breadcrumb\":{\"@id\":\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#primaryimage\",\"url\":\"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/10\/ci4-rest-apis-v2.png\",\"contentUrl\":\"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/10\/ci4-rest-apis-v2.png\",\"width\":1200,\"height\":675},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/naveedshahzad.net\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Designing a RESTful API in CodeIgniter 4 with Authentication, Rate Limiting, and Logging\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/naveedshahzad.net\/blog\/#website\",\"url\":\"https:\/\/naveedshahzad.net\/blog\/\",\"name\":\"Blogs - Naveed Shahzad\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/naveedshahzad.net\/blog\/#\/schema\/person\/2a4d03da05dae472db9d17f993781b04\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/naveedshahzad.net\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/naveedshahzad.net\/blog\/#\/schema\/person\/2a4d03da05dae472db9d17f993781b04\",\"name\":\"naveedshahzad\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/naveedshahzad.net\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/09\/logo-01-updated.jpg\",\"contentUrl\":\"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/09\/logo-01-updated.jpg\",\"width\":1200,\"height\":630,\"caption\":\"naveedshahzad\"},\"logo\":{\"@id\":\"https:\/\/naveedshahzad.net\/blog\/#\/schema\/person\/image\/\"},\"description\":\"Experienced Web &amp; WordPress Developer specializing in custom themes, plugins, eCommerce solutions, and API integrations. Explore projects showcasing front-end and back-end development expertise, tailored to meet unique business needs.\",\"sameAs\":[\"https:\/\/naveedshahzad.net\/\",\"https:\/\/www.facebook.com\/naveed.shahzad.35728\",\"https:\/\/www.instagram.com\/naveed.shahzad94\/\",\"https:\/\/www.linkedin.com\/in\/naveed-shahzad-338b10140\/\",\"https:\/\/x.com\/NaveedS92080775\"],\"honorificPrefix\":\"Mr\",\"birthDate\":\"1994-10-15\",\"gender\":\"male\",\"knowsAbout\":[\"HTML\",\"CSS\",\"Bootstrap\",\"jQuery\",\"PHP\",\"CodeIgniter\",\"WordPress\",\"Ecommerce\",\"WordPress Plugin Development\",\"WordPress Theme Development\",\"AJAX\",\"MySQL\"],\"knowsLanguage\":[\"English\",\"Urdu\"],\"jobTitle\":\"Full Stack Developer\",\"url\":\"https:\/\/naveedshahzad.net\/blog\/author\/naveedshahzad\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Build a RESTful API in CodeIgniter 4 with JWT & Logging","description":"Learn to build a secure RESTful API in CodeIgniter 4 with JWT authentication, rate limiting, and logging using modern best practices.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/","og_locale":"en_US","og_type":"article","og_title":"Designing a RESTful API in CodeIgniter 4 with Authentication, Rate Limiting, and Logging","og_description":"Learn to build a secure RESTful API in CodeIgniter 4 with JWT authentication, rate limiting, and logging using modern best practices.","og_url":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/","og_site_name":"Blogs - Naveed Shahzad","article_publisher":"https:\/\/www.facebook.com\/naveed.shahzad.35728","article_author":"https:\/\/www.facebook.com\/naveed.shahzad.35728","article_published_time":"2025-10-27T11:54:36+00:00","article_modified_time":"2025-10-27T12:12:49+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/10\/ci4-rest-apis-v2.png","type":"image\/png"}],"author":"naveedshahzad","twitter_card":"summary_large_image","twitter_creator":"@NaveedS92080775","twitter_site":"@NaveedS92080775","twitter_misc":{"Written by":"naveedshahzad","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#article","isPartOf":{"@id":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/"},"author":{"name":"naveedshahzad","@id":"https:\/\/naveedshahzad.net\/blog\/#\/schema\/person\/2a4d03da05dae472db9d17f993781b04"},"headline":"Designing a RESTful API in CodeIgniter 4 with Authentication, Rate Limiting, and Logging","datePublished":"2025-10-27T11:54:36+00:00","dateModified":"2025-10-27T12:12:49+00:00","mainEntityOfPage":{"@id":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/"},"wordCount":533,"commentCount":0,"publisher":{"@id":"https:\/\/naveedshahzad.net\/blog\/#\/schema\/person\/2a4d03da05dae472db9d17f993781b04"},"image":{"@id":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#primaryimage"},"thumbnailUrl":"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/10\/ci4-rest-apis-v2.png","articleSection":["Custom Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/","url":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/","name":"Build a RESTful API in CodeIgniter 4 with JWT & Logging","isPartOf":{"@id":"https:\/\/naveedshahzad.net\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#primaryimage"},"image":{"@id":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#primaryimage"},"thumbnailUrl":"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/10\/ci4-rest-apis-v2.png","datePublished":"2025-10-27T11:54:36+00:00","dateModified":"2025-10-27T12:12:49+00:00","description":"Learn to build a secure RESTful API in CodeIgniter 4 with JWT authentication, rate limiting, and logging using modern best practices.","breadcrumb":{"@id":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#primaryimage","url":"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/10\/ci4-rest-apis-v2.png","contentUrl":"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/10\/ci4-rest-apis-v2.png","width":1200,"height":675},{"@type":"BreadcrumbList","@id":"https:\/\/naveedshahzad.net\/blog\/build-restful-api-codeigniter4-jwt-logging\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/naveedshahzad.net\/blog\/"},{"@type":"ListItem","position":2,"name":"Designing a RESTful API in CodeIgniter 4 with Authentication, Rate Limiting, and Logging"}]},{"@type":"WebSite","@id":"https:\/\/naveedshahzad.net\/blog\/#website","url":"https:\/\/naveedshahzad.net\/blog\/","name":"Blogs - Naveed Shahzad","description":"","publisher":{"@id":"https:\/\/naveedshahzad.net\/blog\/#\/schema\/person\/2a4d03da05dae472db9d17f993781b04"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/naveedshahzad.net\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/naveedshahzad.net\/blog\/#\/schema\/person\/2a4d03da05dae472db9d17f993781b04","name":"naveedshahzad","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/naveedshahzad.net\/blog\/#\/schema\/person\/image\/","url":"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/09\/logo-01-updated.jpg","contentUrl":"https:\/\/naveedshahzad.net\/blog\/wp-content\/uploads\/2025\/09\/logo-01-updated.jpg","width":1200,"height":630,"caption":"naveedshahzad"},"logo":{"@id":"https:\/\/naveedshahzad.net\/blog\/#\/schema\/person\/image\/"},"description":"Experienced Web &amp; WordPress Developer specializing in custom themes, plugins, eCommerce solutions, and API integrations. Explore projects showcasing front-end and back-end development expertise, tailored to meet unique business needs.","sameAs":["https:\/\/naveedshahzad.net\/","https:\/\/www.facebook.com\/naveed.shahzad.35728","https:\/\/www.instagram.com\/naveed.shahzad94\/","https:\/\/www.linkedin.com\/in\/naveed-shahzad-338b10140\/","https:\/\/x.com\/NaveedS92080775"],"honorificPrefix":"Mr","birthDate":"1994-10-15","gender":"male","knowsAbout":["HTML","CSS","Bootstrap","jQuery","PHP","CodeIgniter","WordPress","Ecommerce","WordPress Plugin Development","WordPress Theme Development","AJAX","MySQL"],"knowsLanguage":["English","Urdu"],"jobTitle":"Full Stack Developer","url":"https:\/\/naveedshahzad.net\/blog\/author\/naveedshahzad\/"}]}},"_links":{"self":[{"href":"https:\/\/naveedshahzad.net\/blog\/wp-json\/wp\/v2\/posts\/413","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/naveedshahzad.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/naveedshahzad.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/naveedshahzad.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/naveedshahzad.net\/blog\/wp-json\/wp\/v2\/comments?post=413"}],"version-history":[{"count":11,"href":"https:\/\/naveedshahzad.net\/blog\/wp-json\/wp\/v2\/posts\/413\/revisions"}],"predecessor-version":[{"id":429,"href":"https:\/\/naveedshahzad.net\/blog\/wp-json\/wp\/v2\/posts\/413\/revisions\/429"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/naveedshahzad.net\/blog\/wp-json\/wp\/v2\/media\/428"}],"wp:attachment":[{"href":"https:\/\/naveedshahzad.net\/blog\/wp-json\/wp\/v2\/media?parent=413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/naveedshahzad.net\/blog\/wp-json\/wp\/v2\/categories?post=413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/naveedshahzad.net\/blog\/wp-json\/wp\/v2\/tags?post=413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}