ferlrp
ferlrp

Reputation: 21

Change HTTP Status Code in Genexus Procedure Rest

Does anyone know how to change response HTTP Status Code in a procedure type REST in Genexus?

I generated an api rest and it is always responding Http code 200, and I need to change the response to 400 when there is an error.

Upvotes: 2

Views: 1068

Answers (1)

Leandro Minatel
Leandro Minatel

Reputation: 106

API object is available in Genexus 17 for Net and Net Core generators, and GeneXus 17 Upgrade 2 for Java generator. API Object allows you to customize the HTTP Status Code through a predefined variable called &RestCode. Here the wiki for the API Object. If you're using an older version, there is a way to solve the problem writting external code directly in the PRC as explained here.

Depending wich generator are you using the external code is something like this:

.Net generator:

CSHARP [!&httresponse!].Response.StatusCode = 406;

Java generator:

&statusCode = 200
java context.getHttpContext().getResponse().setStatus([!&statusCode!]);

Ok, that code doesn't seems to work in GeneXus Evolution 3 when the PRC is exposed as REST. Doing a little research in the Java Generator, you can modify the StatusCode this way:

enter image description here

And the rules are:

enter image description here

It's a very simple PRC exposed as REST who takes a number as input and generates a String with that number. Don't know exactly how to do that in Net generator.

Upvotes: 4

Related Questions