What are the advantages of RestMessageV2 over GlideHTTPRequest when invoking web services ?

venuvajjala
ServiceNow Employee
ServiceNow Employee

I want to invoke a rest service. I would like to see which API is a better option, RestMessageV2 or GlideHTTPRequest.

Are there some specific contexts where each of them have better advantages.

3 REPLIES 3

Rishi18
Kilo Expert

Hi Venu,



Did you find the differences yet?
The major advantage of using RestMessageV2 is that we can also use it in scoped applications.



Thanks


andrewrump
Mega Contributor

Hi Venu



I can imagine that if you (setup and) use oAuth, RestMessageV2 will handle oAuth token expiration, etc. without you need to write any extra code.



Br


Andrew


TylerTeter
Kilo Guru

RestMessageV2 supports being called from a scoped application, and has built in methods for adding parameters and headers, such as authorization headers. It also has better method support for handling responses and errors.

GlideHTTPRequest doesn't have scoped support, only is supported in global, and doesn't have those built in methods - it's more of a raw request that you can use to get quick information like a ping or health check, that doesn't require any auth headers (otherwise you have to code and add it yourself).

Likely for over 90% of use cases, you want to use RestMessageV2, but for the odd chance you just need something super basic and simple, and you're in global (or have a global wrapper), then you may want to use GlideHTTPRequest.