19 - PHP MVC Frameworks Rest API
19 - PHP MVC Frameworks Rest API
Table of Contents
2
RESTFUL WEB SERVICES
• Request methods:
– GET - Get resource
– POST - Create resource
– PUT - Update resource
– PATCH - Partly update resource
– DELETE - Delete resource
– HEAD - Get headers for resource
• Response: json, xml
5
CRUD Operations in REST APIs
6
RESTful Web Services and HTTP Methods
10
REST Controllers
11
REST Controllers
12
REST Controllers
• GET method
13
REST Controllers
• GET method
14
REST Controllers
• GET by Id method
15
REST Controllers
• GET by Id method
16
REST Controllers
• POST method
17
REST Controllers
• POST method
18
REST Controllers
• DELETE method
19
REST Controllers
• DELETE method
20
REST Controllers
• PUT method
21
REST Controllers
• PUT method
22
RESTful API – Example
Server
Auth
Register
Web Client (JavaScript and jQuery)
Login
$.post("api/register", credentials, 'json');
Operations
$.post("api/login", credentials, 'json');
Users
$.getJSON("api/users");
Remove User
23
JSON
24
Summary
§ REST
§ Rest concepts
§ Rest URIs
§ Responses
§ CRUD Operations and HTTP Methods
25