Andrew Canfield
hi.
Instead it has evolved into full web applications with dynamic content beyond anything developers in the early 90s could even dream about.
More devices.
More interactivity.
More functionality.
multi-tier, multi-client development
=
inefficient, insecure, inextensible
inefficient.
Programmers aren't perfect.
insecure.
Users have grown to expect access on all devices.
Somehow this is always a shock to developers.
inextensible.
Web development needs to efficient, secure, extensible.
Web development needs to be simple.
an abstraction of generic functionality that can be used as the foundation of a larger program.
A semantic language to structure the content.
A formatting language used to describe the content.
A programming language for adding behavior to the content.
Allows data to be retrieved from a server without a page refresh.
A light-weight data-interchange format.
A W3C recommendation to provide a way for web servers to support cross-site access which has been previously restricted by modern browsers due to security concerns.
Model - manages behavior and data
View - manages the display of information
Controller - interprets input and output
and updates model and view
Create, Read, Update, and Delete
authors, articles, comments, tags, and topics
class Controller {
public function create($params) {
...
}
public function read($params) {
...
}
public function update($params) {
...
}
public function delete($params) {
...
}
}
Changes?
New device?
New changes?
no set rules.
Changes?
New device?
New changes?
A specification for exchanging XML-based information by exposing application logic through custom interfaces.
Ignores the details of implementation and syntax. Provides access to CRUD functionality through a standard interface using existing HTTP methods.
Resource |
Get (read) |
Post (create) |
Put (update) |
Delete (delete) |
---|---|---|---|---|
/blog/ | lists all blogs | creates a blog | n/a | n/a |
/blog/123 | retrieves blog 123 | n/a | updates blog 123 | deletes blog 123 |
OPTIONS
Requests information about an entity including default value, validation, and type.
{
"status": "success",
"status_code": "200",
"method": "OPTIONS",
"data": {
"author": {
"value": null,
"required": true,
"validation": "^(\\w|\\d|\\s){1,255}$",
"class": "String"
},
"title": {
"value": null,
"required": true,
"validation": "^(\\w|\\d|\\s){1,255}$",
"class": "String"
},
"date": {
"value": null,
"required": true,
"validation": "^\\d{4}-\\d{2}-\\d{2}$",
"class": "Date"
},
"post": {
"value": null,
"required": true,
"validation": "^.*$",
"class": "TextArea"
},
"comments": [
],
"_id": null,
"groups": [
],
"permission": "private",
"class": "Blog"
}
}
Reflection - the ability of a computer program to examine and modify its structure and behavior dynamically.
Document-oriented storage, full index support, high availability, auto-sharding, GridFS, ad-hoc querying, and MapReduce.
Used to rewrite or redirect URIs based on a series of rules and conditions consisting of server variables, flags, and regular expressions.
%{VARIABLE_NAME}
%{HTTP:VARIABLE_NAME}
%{HTTP:X-Requested-With}
Andrew | Internet |
---|---|
1 | 0 |
# Disallow Directory Listings
Options -Indexes
RewriteEngine On
# API
# Final
RewriteRule ^api/index.php/(\w+)/(\w+)/? api/index.php [L,NC,QSA,E=CONTROLLER:$1,E=ID:$2]
# API
# :controller/:id
RewriteCond %{REQUEST_METHOD} ^(OPTIONS|PUT|DELETE|POST|GET)
RewriteCond %{HTTP:X-Requested-With} !^$
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^/?(.*)/(.*)/?$ api/index.php/$1/$2 [QSA,L]
# API
# :controller
RewriteCond %{REQUEST_METHOD} ^(OPTIONS|PUT|DELETE|POST|GET)
RewriteCond %{HTTP:X-Requested-With} !^$
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^/?(.*)/?$ api/index.php/$1/NULL [QSA,L]
# CORS preflight
RewriteCond %{REQUEST_METHOD} ^OPTIONS
RewriteRule ^.*$ api/index.php [L,E=CORS:TRUE]
# Block all Request Methods not directed to API
RewriteCond %{REQUEST_METHOD} ^(OPTIONS|PUT|DELETE|POST)
RewriteRule .* - [F]
# Mobile Client
RewriteCond %{HTTP_USER_AGENT} iphone|ipad|android|blackberry [NC]
RewriteCond %{REQUEST_METHOD} ^GET
RewriteCond %{HTTP:X-Requested-With} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ mobile/index.php?$1 [QSA,L]
# Web Client
RewriteCond %{REQUEST_METHOD} ^GET
RewriteCond %{HTTP:X-Requested-With} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/index.php?$1 [QSA,L]
Each client is responsible for the functionality and presentation required by its implementation.
{
"status": "success",
"status_code": "200",
"method": "OPTIONS",
"data": {
"author": {
"value": null,
"required": true,
"validation": "^(\\w|\\d|\\s){1,255}$",
"class": "String"
},
"title": {
"value": null,
"required": true,
"validation": "^(\\w|\\d|\\s){1,255}$",
"class": "String"
},
"date": {
"value": null,
"required": true,
"validation": "^\\d{4}-\\d{2}-\\d{2}$",
"class": "Date"
},
"post": {
"value": null,
"required": true,
"validation": "^.*$",
"class": "TextArea"
},
"comments": [
],
"_id": null,
"groups": [
],
"permission": "private",
"class": "Blog"
}
}
method(params, callback)
method(params, callback, callback)
method(params, callback, callback, callback, ..., callback)
The Promise interface represents a proxy for a value not necessarily known when the promise is created. It allows a programmer to associate handlers to an asynchronous action's eventual success or failure which allows asynchronous methods to return values like synchronous methods: instead of the final value, the asynchronous method returns a promise of having a value at some point in the future.
method(params)
.then(function)
.then(function)
...
.then(function)
Let's do this.
Andrew Canfield