Welcome Guest, Not a member yet? Register   Sign In
REST API, is CI for me?
#1

Just came across CodeIgniter this morning and I am intrigued by it, I am wondering if I could use it to "improve" upon my manual coding of php "REST" functions like the following?

PHP Code:
<?php
 
require_once 'DB_Functions.php';
$db = new DB_Functions();

$response = array("error" => FALSE);

if (isset(
$_POST['id'])) {

    $id $_POST['id'];
$price $_POST['price'];
$clientid $_POST['clientid'];

if (
$db->isCheckedOut($clientid) == false)

$result $db->addToCart($id$clientid$price);

echo 
json_encode($result);
}
else
{
$result "invalid";
echo 
json_encode($result);
}
}
?>

I am calling it in a mobile app using ajax:
Code:
function addToCart($menuID, $price, $clientID)
{
var dataString = "id=" + $menuID + "&price=" + $price + "&clientid=" + $clientID;
$.ajax({
type: "POST",
url: serviceURL + "addToCart.php",
data: dataString,
crossDomain: true,
cache: false,
success: function(data) {

From my initial understanding, CI seems to be a "complete" package where I could create my "frontend" and "backend", is that correct? Could I not use it for "backend" purposes only? Like exposing a "Web Service" or "REST" API that I could call either in mobile or a "web" application?

TIA
Reply


Messages In This Thread
REST API, is CI for me? - by dee-u - 02-07-2020, 06:50 PM
RE: REST API, is CI for me? - by donpwinston - 02-07-2020, 10:11 PM
RE: REST API, is CI for me? - by jreklund - 02-08-2020, 12:47 AM
RE: REST API, is CI for me? - by dee-u - 02-08-2020, 03:35 AM
RE: REST API, is CI for me? - by InsiteFX - 02-08-2020, 08:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB