DEV Community

Cover image for Create A REST API In Codeigniter With Basic Authentication

Create A REST API In Codeigniter With Basic Authentication

pardeep on March 28, 2018

The CodeIgniter RESTful API is a set of simple, modular helpers that can be easily integrated into your CodeIgniter projects, allowing you to creat...
Collapse
 
zamfir80 profile image
Razvan Zamfir • Edited

I have made a small blogging application in Codeigniter 3. I have recently separated its back-end (dashboard) from the frontend.

I would like to give up on loading views in the frontend and spit-out JSONS instead. Further, I would like to use Vue to handle the frontend (JSON).

The issue is described in detail here. Please give me a hand.

Thanks!

Collapse
 
vimuth7 profile image
vimuth • Edited

Thanks so much I learned a lot from here. And I think we can use wget linux command to get Libraries and config files from codeigniter-restserver. in "Setting up Libraries and Permissions" section you can do this,

cd codeigniter/applications/libraries
wget https://raw.githubusercontent.com/ardisaurus/ci-restserver/master/application/libraries/REST_Controller.php
wget https://raw.githubusercontent.com/chriskacerguis/codeigniter-restserver/master/applic
es/Format.php
cd codeigniter/applications/config
wget https://raw.githubusercontent.com/chriskacerguis/codeigniter-restserver/master/application/config/res
t.php

Here what I have done is downloaded those files with wget command using raw view of those github files

Thanks,
Vimuth

Collapse
 
ulisesescamilla profile image
Ulises Escamilla

Thanks pardeep!,

I have a question and I'm so confused, what's the difference between password on the User's table, the rest_valid_logins in the rest.php file and the API Key in the Key's table. Can you help me please?

Collapse
 
dasuccess profile image
DASUCCESS

Hy, i was hoping you can help me on the current project i am on, i have been trying to write an affiliate code for code igniter 4, affiliate to register under affiliate. once a user is registered a referral link is generated and then other user can use the link to generate there own and register as an affiliate under the first person, can you help with some code to execute this, thanks

Collapse
 
azcodez profile image
azcodez

Thanks Pardeep

Do you have to do route.php?

Thanks
Az

Collapse
 
mikerico profile image
Maicol Romero

thanks for the help bro

Collapse
 
mslabba profile image
Muhammed Shihabudeen Labba

Thanks for the detailed article.

But when I try to access the API even using 'No Auth' it is working.

Collapse
 
emmanuelmuthui profile image
EmmanuelMuthui

I have created my api, but am trying to use the users from database to login as opposed to hardcoding username as admin and password as 1234.

How can i go about it kindly?

Collapse
 
aasiimwedatacare profile image
Asiimwe Apollo

Thanks Pardeep

Collapse
 
ogisetiawan profile image
ogisetiawan

thanks Boom!,

simple module,

Collapse
 
azcodez profile image
azcodez

Thanks Pardeep

Do you know how to add Oauth2.0 to authenticate?

Collapse
 
deogit profile image
deogit

Can you explain what is basic authentication?
Where we can set the admin and password?

Collapse
 
deogit profile image
deogit

Got it!

Just saw it in $config['rest_valid_logins'] = ['admin' => '1234'];