24
Views
3
Comments
Solved
REST API, OnRequest: can I still add an URL parameter here?
Question
Application Type
Service

Hello,

I'd like to implement such a scenario:

  • expose a REST API
  • create some methods of it; each of them needs a parameter, let it be named: MyIdentifier
  • I cannot send this parameter explicitly; I can send only a corresponding code and then find the identifier corresponding to it
  • but I don't want to do it in each of the exposed methods (each method would have MyCode parameter and find  MyIdentifier based on it)
  • the idea is to send MyCode in a header, read it in OnRequest and then - add to the resulting Request an additional parameter, that is: MyIdentifier
  • when I create an OnRequest handler it is scaffolded and already has an assignment: CustomizeRequest (output) = Request (input); it suggests that manipulating Request is still possible
  • but the input Request is a plain text and is always empty

So, there are two questions:

  • is my scenario possible to implement? maybe it is too late to modify Request, especially - to add parameters?
  • when it is possible - how to manipulate the request in an OnRequest handler?

Regards

Tomasz

Solution

Hi Tomasz,

I don't quite get your scenario, so let's see if I understand: you expose a REST API, and each method has an input, which is a code. This code is sent by the consumer of the method. However, in your OutSystems code you need to convert this code to an identifier for easy later processing. You do not want to explicitly code that each time in the OutSystems code in the methods, but instead want to rely on pre-processing in OnRequest. Am I right so far?

Anyways, OnRequest, as opposed to OnBeforeRequest of a consumed REST API, is pretty spartan: you have access to the request body, and that's it. No access to headers, no access to the URL. So there's very little you can do there. Also, for GET methods you do not even have a body, as all parameters are in the URL by definition. So I'm afraid the only thing you can do is just explicitly convert the code to an Id in every method.



Hi Kilian,

Thanks for the explanations. They confirm my suspicions :-). The Outsystems' documentation is a little bit misleading - it promises too much.

Regards

Tomasz

Yeah, the documentation is not ideal here, and I don't understand why OnRequest doesn't have the same possibilities as OnBeforeRequest. But anyway, thanks I could be of (limited) help. Happy coding!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.