4

I need to create a REST (or REST-like) API for my SF application. After reading https://salesforce.stackexchange.com/a/19058/3382, my thought was to simply use the @RestResource annotated classes because I'd like to not recreate what SF provides out-of-the-box.

However, due to my sharing model, I cannot allow access to the standard SF REST API which is a byproduct of using the annotated classes.

I'm thinking I could come close to creating the REST-like service but I need to know the appropriate HTTP verb (GET, POST, PUT, DELETE) used for the request. But I can't figure out what the verb is in my Apex controller. ApexPages.currentPage().getHeaders() doesn't contain the verb and ApexPages.currentPage().getHeaders() is just a combined map of post and url parameters.

Have I hit the end of the road with this approach? Am I restricted to just create a JSON based API using only GETs and POSTs?

  • I just realized this question was my fault. Irony, I suppose. – sfdcfox Nov 8 '13 at 1:36
2

You can't get to the HTTP verb in Visualforce, nor can you even influence something simple like the status code. Given the rather severe limitations in place, you'll have to be a bit more creative. You can, for example, set a 'X-HTTP-Verb' header that you could read in Visualforce (with the true action always set to GET or POST). You could also include it as a URL parameter or as part of the payload. Yes, I realize it's not a "true REST" solution, but we're working within the bounds of the platform. Also remember that your payload has to be url encoded with normal name-value pairs to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.