I have an Apex class implementing a simple REST GET method
@RestResource(urlMapping='/myrest/*')
global class MyResService {
@HttpGet
global static CustomObject__c doGet() {
..
}
}
and a Visualforce page including Javascript code that requests this service's (JSON result)
<apex:includeScript value="{!$Resource.jquery_min_js}" />
<script type="text/javascript">
$j = jQuery.noConflict();
$j.ajax({
url: '{!InstanceUrl}/services/apexrest/myrest',
type: 'GET',
dataType: 'json',
error: function() { console.log(error); },
success: function() { alert('hello!'); },
beforeSend: setHeader
});
function setHeader(xhr) {
xhr.setRequestHeader("Authorization", "OAuth {!OAuthToken}");
}
...
My question now is how to I get the {!OAuthToken} and {!InstanceUrl}? I have seen quite complex solutions that seem to be required when calling ANOTHER ORG's service. I need the simple ONE ORG solution ;).
{!$Api.Enterprise_Server_URL_270}
and{!$Api.Session_ID}
any good?