Welcome Guest, Not a member yet? Register   Sign In
A Complete REST API Tutorial
#1

Hello, is there a fully completed example project or tutorial?

I'm trying to build REST API test in CI4. 

I've tried the steps described here : https://codeigniter4.github.io/userguide...stful.html 

But unfortunately when I try to reach controller, it's returning as an empty XML file. What do I missing? 

I was expecting a JSON file that contains data. 

I've never worked with APIs before. So I would be happy if you could explain it simply. 

I've used to following code: (I'm connected to database and I can see the raw data with "print_r")


Controller
PHP Code:
<?php 

namespace App\Controllers;

use 
CodeIgniter\RESTful\ResourceController;

class 
Categories extends ResourceController {

    public function 
__construct() {
        
$this->modelName 'App\Models\Categories';
    }

    public function 
index()    {
        
$this->respond($this->model->findAll(),200);
    }
    



Model
PHP Code:
<?php

namespace App\Models;

use 
CodeIgniter\Model;

class 
Categories extends Model {
    protected 
$table 'categories';


Routes
PHP Code:
$routes->resource('categories'); 
Reply


Messages In This Thread
A Complete REST API Tutorial - by Philos - 09-07-2019, 02:27 PM
RE: A Complete REST API Tutorial - by ciadmin - 09-07-2019, 02:35 PM
RE: A Complete REST API Tutorial - by mintwint - 09-07-2019, 11:31 PM
RE: A Complete REST API Tutorial - by atsanna - 09-08-2019, 01:55 AM
RE: A Complete REST API Tutorial - by myo - 03-25-2020, 03:58 AM
RE: A Complete REST API Tutorial - by monkenWu - 04-10-2020, 04:53 AM
RE: A Complete REST API Tutorial - by anmar_dev - 04-17-2020, 02:24 AM



Theme © iAndrew 2016 - Forum software by © MyBB