What is the difference between REST and RESTful?

16

I understand that they are architectures and that the idea of these is once downloaded the web page this does not re-download any HTML or CSS or JS if not, that only makes calls or requests and is answered with JSON

    
asked by MarcoAndresito 13.01.2016 в 23:15
source

3 answers

21

REST (Representational State Transfer) is an architecture that runs over HTTP.

RESTful refers to a web service that implements the REST architecture.

In a fairly basic example (of creating a RESTful application), we have a project where we implement a CRUD for houses in PHP and with the MVC architecture, the result of the answers will be returned in JSON, but it is not obligatory to manage only that type Content-type , you can return HTML, text, etc ...

My model would be something like:

namespace modelos\Casa;

use common\Model;

class Casa extends Model
{

    public function getId($id)
    {
        // Carga una casa por ID
        return ['id' => 1, 'puertas' => 1, 'focos' => 5];
    }

    public function getAll()
    {
        // Carga DB y devuelve todas las casas
        return [
            ['id' => 1, 'puertas' => 1, 'focos' => 5],
            ['id' => 2, 'puertas' => 1, 'focos' => 3],
            ['id' => 3, 'puertas' => 2, 'focos' => 8]
        ];
    }

    public function delete($id)
    {
        // Elimina un registro en la DB
        return parent::delete($id);
    }

    public function save()
    {
        // Valida que todo sea correcto y devuelve un booleano
        return parent::save();
    }

}

My driver something like:

namespace controladores\Casas;

use modelos\Casa;
use common\Controller;

header('Content-Type: application/json');

class Casas extends Controller
{

    public function actionPost($id)
    {
        $casa = Casa::findId($id);
        $casa->loadParams($_POST);

        echo json_encode(['success' => $casa->save()]);
    }

    public function actionGet($id = null)
    {
        if (isset($id)) {
            echo json_encode(Casa::getId($id));
        } else {
            echo json_encode(Casa::getAll());
        }
    }

    /* Aquí el demás código */

}

The 3rd. part could handle it with JavaScript and HTML, where the JS would send the request through AJAX to obtain a result and show it to the user in a friendly way.

Requests could be made to the resources listed below with the corresponding HTTP status and the controller would be responsible for responding to each of them.

Additional information at:

answered by 14.01.2016 / 03:25
source
6

REST (Representational State Transfer or Representational State Transfer) is a style of software architecture, which not only consists of responding json, but can also respond to another data exchange format such as xml.

But apart from just responding in an exchange format other than HTML, REST involves other concepts such as:

  • Resources which can be accessed using a global identifier (URI)
  • Well defined operations to create, read, update and delete
  • Work under a client-server protocol without a state, as it is HTTP which means that each HTTP message contains all the information necessary to understand the request.

REST is much more than I just mentioned, so it would be good if you read something more about what REST really is and do not just stay with the idea that REST is only to answer JSON requests.

RESTful is often used to refer to web services that run the REST architecture.

Additional information:

answered by 14.01.2016 в 03:39
1

REST is an "architectural style" that basically exploits the technology and protocols of the existing Web.

RESTful is often used to refer to web services running such an architecture.

    
answered by 13.01.2016 в 23:23