Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New to REST API

basically I have been assigned to build a REST request application in PHP, using a 3rd party REST API. Doing POSTs, GETs etc seems simple, however they have something called an Authorization header which uses a Digest token. How do I pass this via a get?

EG:

$url = "http:/domain/core.xml";
$response = file_get_contents($url);
echo $response;

Returns : Digest auth headers not found

In FireFoxes POSTER i would simply add the header "Authorization" with the value "Digest 0:codehere" and it works.

like image 893
rickyduck Avatar asked May 19 '11 12:05

rickyduck


People also ask

What is REST API beginner?

It is a standard that guides the design and development of processes which enable us interact with data stored on a web servers. The above definition may not look as complex or "professional" as the ones you come across on the internet, but the goal here is for you to understand the basic purpose of REST APIs.

Is REST API difficult to learn?

Easy to Learn and Implement REST uses HTTP methods for communication and most of us are familiar with the HTTP verbs such as GET, POST, PUT or DELETE. These methods are self-explanatory that what it does (in case if you don't know these terms) and that makes REST easy to learn.


1 Answers

See file_get_contents()

string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )

The third argument $context allows you to add a context create by stream_context_create(). See HTTP context options. There you can find an option header, that allows you to set headers to be used by the request you send, in your case the Authorization-header

like image 138
KingCrunch Avatar answered Sep 19 '22 12:09

KingCrunch