Covers the concepts on how to build a web service (Rest API), data formats (JSON vs XML), HTTP, troubleshooting your API, tools and how to bring it all together in PHP.
Nell’iperspazio con Rocket: il Framework Web di Rust!
How To Build A Web Service
1. HOW {TO}
BUILD A WEB SERVICE
1
Sunday, October 9, 11
2. OVERVIEW
I. REST API
II. DATA FORMATS - (JSON vs XML)
III. Request
IV. Response
2
Sunday, October 9, 11
3. NEED TO KNOW
I. HTTP
I. Methods
II. Headers
III. Status Codes
3
Sunday, October 9, 11
4. HOW TO
I. Troubleshooting
II. Tools
III. PHP Frameworks
4
Sunday, October 9, 11
5. /**
* Representational State Transfer
*/
REST
5
Sunday, October 9, 11
6. /**
* Representational State Transfer
*/
- use HTTP methods to determine action.
- use HTTP headers identify specifics of
the request and how to handle the
response
6
Sunday, October 9, 11
8. /**
* USEFUL HTTP HEADERS
*/
- Accept and Content-Type: used for content format
negotiation
- User-Agent: Identify what made the request
8
Sunday, October 9, 11
9. /**
* HTTP STATUS CODES
*/
- 200: OK - 404: Not Found
- 301: Moved - 500: Server Error
- 302: Found - Custom *
- 401: Not Authorized
- 403: Forbidden
9
Sunday, October 9, 11
10. /**
* JSON vs XML
*/
DATA FORMATS
10
Sunday, October 9, 11
11. /**
* JSON: JavaScript Object Notation
*/
Pros
- Comes standard in PHP
- Light
- Great for devices
11
Sunday, October 9, 11
12. /**
* JSON: JavaScript Object Notation
*/
Cons
- Hard to distinguish Object vs Array in php
- Not as descriptive
12
Sunday, October 9, 11
13. /**
* XML
*/
Pros
- Verbose and Precise
- Great for Machine to Machine
- Inherent style depending on the client.
13
Sunday, October 9, 11
14. /**
* XML
*/
Cons
- Heavy
- Multiple PHP libraries / parsers
- Multiple standard formats (plain, rss, atom etc)
14
Sunday, October 9, 11
15. /**
* Request and Respond
*/
- Resource are always in plural
http://api.local.ws/users/1
- When no identifier is present, the collection is the
resource
http://api.local.ws/users
- Respond with appropriate status code
15
Sunday, October 9, 11