As we have learned from this chapter, creating an API is a very large topic, one which is covered in greater detail in a number of books dedicated to the subject. Let's look at how we can quickly consume our new API using cURL (http://www.php.net/manual/en/intro.curl.php).
With cURL, we can pass our username and password, and it will handle passing the appropriate values to authenticate against the basic authentication we have in place.
First, we need to set our username, password, and the URL we wish to connect to.
$username = 'michael'; $password = 'password'; $url = "http://localhost/api/users";
Next, we initialize a connection to the URL.
$ch = curl_init($url);
We then set a number of options, including the username and password, ...