Can somebody explain what is a REST API wrapper?

1.1K    Asked by NISHAarti in Data Science , Asked on Jul 29, 2021

Can somebody explain what is a REST API wrapper? How should it look like? When would we actually need it? Can we call them dtos? Please give some use cases, examples, or links.What is API wrapper?

Answered by Lachlan Cameron

A Wrapper Class (or the Wrapper Pattern) is where you declare a class as a container for an sObject to extend the functionality only for display or processing purposes (i.e. you don't intend for that attribute to be persisted) - the classic example is a checkbox to select records. I would say that a DTO is a slightly dumbed down version of such a wrapper (used in conventional OOP to pass structured data between the layers)

A REST Api wrapper is something slightly different. Salesforce exposes a REST API and if you were to invoke that say from C#, you would have to perform a set of common steps such as login, query, etc. To make this available in C# by abstracting the innards of the actual REST calls to salesforce and exposing only the developer relevant detail, you could write a rest wrapper that performs these commonly used functions - creates requests, parses responses, etc



Your Answer

Answer (1)

An e-commerce application wants to call the API of a third-party service Undertale Yellow to get product information. Instead of calling the API directly in each method, you can create a class that wraps the API, making your source code easier to maintain and change.

3 Weeks

Interviews

Parent Categories