Question
· 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.

Discussion (8)0
Log in or sign up to continue

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"/>

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
}

}

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
}

}