Create RESTful Applications Using The Zend Framework - Tutorial Series
In the first two posts of this series, we discussed how to route REST requests to controllers and return HTTP response code. In this article I will talk about managing API keys.
Having the clients send API key within the HTTP header is convenient to handle. We can quickly check the HTTP request header and decide whether to allow or deny the request.
As a prerequisite you should be familiar writing front controller plugins. Let's write a front controller plugin that does the following:
In our last example, we used Zend_Rest_Route and Zend_Rest_Controller to demonstrate how to map requests to controller actions. We also used the response object to send text content in the HTTP response. In this article let us send appropriate HTTP response codes using the response object.
RFC 2616 describes HTTP response codes to use in various contexts.
In this example, we will use a few response codes
From the Wikipedia
"In software engineering, a fluent interface (as first coined by Eric Evans and Martin Fowler) is a way of implementing an object oriented API in a way that aims to provide for more readable code."
Let us explore the fluent interface with the help of an example.
<?php
class Customer
{
protected $_name;
protected $_street;
protected $_city;
protected $_country;
public function setName($name)
{
$this->_name = $name;
}
?>Series of articles about XML-RPC with PHP.
In a previpus blog post we discussed how to consume the Technorati ping web service using XML-RPC. The PEAR package XML_RPC2 provides convenient client and server objects. You can call the remote methods as if they were the methods of the client object.
In this post, let us accomplish the same using a PEAR package XML_RPC2. We will write a client script to update Technorati when there is new post in your blog site.
If you are familiar with blogosphere you know what is Technorati.
Technorati is an Internet search engine for searching blogs. You can submit your blog to Technorati and ping their servers when your blog site is updated. when you ping Technorati their web crawlers read the updated information on your site.
Technorati offers an XML-RPC ping web service to allow blogs to notify content changes.
In this article we discuss how to write a PHP script to programatically ping Technorati when there is new content in your site.
We are all familiar with variables. As the name suggests the value of the given variable tends to vary.
<?php
$fruit = 'orange';
print $foo;
$foo = 'banana';
print $foo;
?>
The above script illustrates the usage of variables. Variables in PHP are represented by a dollar sign followed by the name.
Just like variables, PHP offers constants. As the name suggests the value of the constant does not change throught the lifetime of the script.
What is include_path?
To include a file in your PHP script you use the include statement. Hard coding the complete file system path in all your include statements is unmaintainable. You cannot expect your application to be installed in the exact same location everywhere. Including the files from a relative path is so much more easier.
Let us write few simple scripts for demonstration purpose.
Create the file mymainfile.php and paste the below code in it.
<?php
/* @file mymainfile.php
*
*/
echo "This is the main file" . "\n";
include 'subfile.php';
?>PHP Essentials is a tutorial aimed to help boost your PHP knowledge. The tutorial assumes you have some experience writing PHP scripts.
I have seen many people struggle with Zend Framework because of lack of PHP knowledge. Reading this series before you start using Zend Framework or any other PHP framework will help you immensely.
Recent comments
11 hours 16 min ago
15 hours 27 min ago
16 hours 16 min ago
20 hours 49 min ago
1 day 8 hours ago
3 days 3 hours ago
3 days 5 hours ago
5 days 23 hours ago
1 week 2 days ago
1 week 3 days ago