class UserController extends Controller
{
private $state_fail = 0;
private $state_success = 1;
private $img_url = 'http://xxx.cn/';
public function __construct()
{
parent::__construct();
$this->appUrl = "http://xxx.cn/" . I("server.HTTP_HOST");
header('Content-Type: application/json; charset=utf-8');
$code = I('code');
if (!$code) {
$code = I('get.code');
}
switch ($code) {
case 1001:
$this->register();
break;
case 1002:
$this->Login();
break;
case 1003:
$this->Forget()
break;
case 1004:
$this->Rem_equip();
break;
default:
break;
}
}
The above is an interface written by a colleague using thinkphp3.*
. I recently saw the concept of RESTful
. Are the two the same thing? If not, what are the differences between the two, which one is better? Thanks!
ThinkPHP: It is a free and open source, fast and simple object-oriented lightweight PHP development framework.
RESTful: A software architecture style, a design style rather than a standard, which just provides a set of design principles and constraints. It is mainly used for client and server interaction software. Software designed based on this style can be simpler, more hierarchical, and easier to implement mechanisms such as caching.
One is a concrete implemented framework, the other is a design idea, one is practice, and the other is theory; of course, theory can eventually become reality.
api and restfulapi are actually interfaces. There are two differences:
1. Restful uses http code to represent status
2. The most important thing about resetful is resource thinking. The reason why it is flexible is that it rarely participates in business logic and only Define resource operations.
It can be understood that RESTful is a design idea of API. Through this idea, a more reasonable and more elegant API can be designed. ps: After reading this code, I want to say that this is not a restful api at all.
Obviously not the same thing! ! But in a narrow sense, we sometimes call the interface an API when interacting with client data, but in fact the definition of API is broader. For example, when we are learning a framework, we will look at its API documentation. At this time, the API is not just a data-related interface, but a method provided to the outside world.
Restful is a form of API implementation. The most obvious feature is that in the interface URL, try to use nouns instead of verbs to express the meaning of the interface. Use the method method provided by http to implement the verb part. GET is used to obtain resources, POST is used to create new resources (it can also be used to update resources), PUT is used to update resources, and DELETE is used to delete resources.