Web Connection User Discussions
REST - how to handle bad requests
Gravatar is a globally recognized avatar based on your email address. REST - how to handle bad requests
  Adam W
  All
  Oct 5, 2021 @ 02:58pm

Hi, I have a REST service with around 30 methods/services defined (WestWindWeb ver 6.05). How to handle requests which are not defined ? EXAMPLE: https://mydomain.com/WestWindService/login.ws works because I have a Function Login defined. If I manually type URL like: https://mydomain.com/WestWindService/somethingUndefined.ws it will crash the REST Server.

Server shows error "Property somethingUndefined.ws not found" and needs manual restart - something I want to avoid... I'd like to catch that before it hits rest process...

Gravatar is a globally recognized avatar based on your email address. re: REST - how to handle bad requests
  Carl Chambers
  Adam W
  Oct 5, 2021 @ 09:45pm

Hi Adam,

You could put something like this in the OnProcessInit() method...

lcFunction = JUSTSTEM(Request.GetPhysicalPath())
IF !PEMSTATUS(THIS,lcFunction,5)
  * call or redirect to a method that returns an error response
  RETURN .F.
ENDIF

Carl

© 1996-2021