Connecting to REST API using Basic Auth The title pretty much says it all. 

I'm trying to connect to a RESTful API within Craft templates to pull various showtimes, prices, availability, etc. of a theater. I have my URL endpoints and username &amp; password but have no idea where they need to go in the templates. The API uses Basic Authentication. Everything I'm reading is PHP specific and I'm not quite sure how that translates to Craft/Twig.

I like the Rest plugin by Dukt (https://dukt.net/rest) but it uses OAuth.

Any help/direction would be appreciated.
I have built something similar so hopefully this will help get you rolling.

You are going to need to (or at least I would) create a plugin that you can call in your twig template. Pay special attention about creating a variable and services.

Let's say your plugin is called theater.
Let's also pretend you have a url "mysite.com/showtimes"

In your showtimes template, you would make a call to your theater plugin to get showtimes.

showtimes.twig

{# Get all upcoming showtimes from the api. #}
{% set showtimes = craft.theater.showtimes %}


I won't get into the specifics of building an entire plugin, but here are the main players you'll need.

First you'll need a file called TheaterVariable.php that has this:

TheaterVariable.php

&lt;?php
namespace Craft;

class TheaterVariable
{
    /**
     * Get all upcoming showtimes from the api.
     *
     * @return mixed
     */
    public function showtimes()
    {
        $showtimes = craft()-&gt;theater-&gt;getShowTimes();

        return $results['data'];
    }
...

}


Now you'll need a file called TheaterService.php to do the real work of getting your showtimes.

TheaterService.php

&lt;?php
namespace Craft;

class TheaterService extends BaseApplicationComponent
{
    /**
     * Get all upcoming showtimes from the api.
     *
     * @return \Guzzle\Http\EntityBodyInterface|string
     */
    public function getShowTimes()
    {
        try {
            error_log((craft()-&gt;config-&gt;get('devMode')) ? 'Getting all upcoming showtimes.' . '' : '');

            $client = new \Guzzle\Http\Client('http://your-api-domain.com/);
            $uri = 'api/api-endpoint';

            $request = $client-&gt;get($uri, array(
                'content-type' =&gt; 'application/json'
            ));

            $request-&gt;addHeader('Accept', 'application/json');
            $request-&gt;addHeader('Authorization', 'YOUR CREDS');

            $response = $request-&gt;send();

            return $response-&gt;json();
        } catch
        (\Exception $e) {
            if (craft()-&gt;config-&gt;get('devMode')) {
                error_log('Error: Could not get upcoming showtimes.');
                error_log($e-&gt;getResponse()-&gt;getBody());
            }
        }

    ...

    }
}


Finally, back to your showtimes template:

showtimes.twig

{% if showtimes|length %}
    {% for showtime in showtimes %}
        ...
    {% endfor %}
{% else %}
    {# Could not find any upcoming showtimes for some reason. #}
{% endif %}


I am using oAuth to handle my authorization, so that part might be a bit different for you. But in the big picture this should be pretty close.

Hope this helps!