Question Roberto Cahanap · Sep 14, 2018

REST POST 405 error

I'm testing out the new %CSP.REST way of creating an api and having a problem with a POST getting a 405 error.

I get data returned when I do a GET, so I don't think it's a configuration issue or a class issue.

I have no problem with %CSP.Page when creating a REST type method. So what am I missing?

Can someone give me some advice?

Thank you.

Comments

Roberto Cahanap  Sep 14, 2018 to Eduard Lebedyuk

Here is what I'm trying right now just to  check if the POST code is working or making it to the method.

The Route:

<Route Url="/test1" Method="POST" Call="Test1"/>

The Method:

ClassMethod Test1() As %Status
{
Set tSC=$$$OK
"test...",!
Quit tSC
}
 

This GET works:

<Route Url="/status/:ClientID" Method="GET" Call="GetActiveStatus"/>

0
Roberto Cahanap  Sep 14, 2018 to Gilberto Junior

How do I allow a method then with %CSP.REST?

0
Eduard Lebedyuk  Sep 14, 2018 to Gilberto Junior

You need to add POST route:

Class Rest.UsuarioSvc Extends %CSP.REST
{

XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
<Routes>
<Route Url="/Oi/:xpto" Method="GET" Call="Oi"/>
<Route Url="/Oi/:xpto" Method="POST" Call="Oi"/>
</Routes>
}

ClassMethod Oi(xpto As %String) As %Status
{
    Set tSC = $$$OK
    
    If 'tSC Quit tSC       
    Set tProxy = ##class(%ZEN.proxyObject).%New()
    Set tProxy.Oi = xpto _ "1234"
    
    Set %response.ContentType = "application/json"
    set %response.Status = 200
    Do tProxy.%ToJSON()
    
    Quit tSC
}

}
0
Roberto Cahanap  Sep 14, 2018 to Gilberto Junior

Hi, it's still not clear. Do I have to define both a GET and  POST for the same Route?

Is that what I'm missing?

0
Gilberto Junior · Sep 14, 2018

Hi.

rror 405 refers to method not allowed.
Probably this being invoked a method that only supports GET as a POST.

0
Eduard Lebedyuk  Sep 14, 2018 to Roberto Cahanap

Do I have to define both a GET and  POST for the same Route?

Yes.

Usually they have different logic so it makes more sense. What's your use case for GET and POST handlers to be the same?

0
Gilberto Junior · Sep 14, 2018

Hi,

Use this Example code

Class Rest.UsuarioSvc Extends %CSP.REST
{

XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ]
{
<Routes>
<Route Url="/Oi/:xpto" Method="GET" Call="Oi"/>
</Routes>
}

ClassMethod Oi(xpto As %String) As %Status
{
    Set tSC = $$$OK
    
    If 'tSC Quit tSC       
    Set tProxy = ##class(%ZEN.proxyObject).%New()
    Set tProxy.Oi = xpto _ "1234"
    
    Set %response.ContentType = "application/json"
    set %response.Status = 200
    Do tProxy.%ToJSON()
    
    Quit tSC
}

}
 

0