Search

How to Create a REST API in Codelgniter with Basic Authentication

  • Share this:
post-title

What is Api ?

API is the acronym for Application Programming Interface, which is a software intermediary that allows two applications to talk to each other.

Mostly, an API provides interactions between one software and another, but not users.

But in cases where it provides user interactions, an application can take the user interface widget and display it. The API is beneficial because it allows for standardization and simplification of data for users.

 

What is REST API ?

REST stands for Representational State Transfer. A REST API is a web service which uses HTTP methods like’s GET, PUT, POST, DELETE and etc.. methods for data manipulation over the cross platforms.

REST suggests to create an object of the data requested by the client and send the values of the object in response to the user.

 

So let’s follow step to create a restful api

Step 1: We have downloaded a codeIgniter and extract inside codeIgniter-api-app folder  

Step 2: Download fresh Codelgniter After downloading the Codelgniter, we run it, then after that, other walks to the next step.

 

Api-1

 

Step 3: After  Download  Codelgniter Now we have to create a Api folder , after that we have to create a Controller file inside the Api folder, named TestApi.php

 

api-2

 

Step 4: Create a class with constructor function and after create class create method any name and After that we make rout to run it so that we can check

 

api-3

 

Step 5: Now we create a method index name inside TestApi.php file 

codeIgniter-api-app > application >controllers > Api > TestApi.php > index 

In this example, you can see this we have run our app successfully 

Step 5: now start we create a rest full controller 

codeIgniter-api-app > application > libraries > API_Controller.php

Create a jwt class JSON Web Token Token is an Internet standard for creating JSON-based access tokens

codeIgniter-api-app > application > libraries > Authorization_Token.php

You click here to download jwt all file and put on codeigniter third_party folder and extract inside codeigniter third_party 

Tags: