Contents
How to create an apex class that calls a rest endpoint?
@Harsh Dodia, just replace your endpoint with this https://th-apex-http-callout.herokuapp.com/animals/’+x, in your code are not using method Parameter at the end of the endpoint string that’s why you were getting null pointer exception. Executing the ‘getAnimalNameById’ method on ‘AnimalLocator’ failed.
How are case records managed in apex class?
Your Apex class manages case records. The class contains five methods, and each method corresponds to an HTTP method. For example, when the client application invokes a REST call for the GET HTTP method, the getCaseById method is invoked.
Which is the default format for Apex Rest?
Apex REST supports two formats for representations of resources: JSON and XML. JSON representations are passed by default in the body of a request or response, and the format is indicated by the Content-Type property in the HTTP header. Since JSON is easier to read and understand than XML, this unit uses JSON exclusively.
How to create an apex Web Services class?
Describe the two types of Apex web services and provide a high-level overview of these services. Create an Apex REST class that contains methods for each HTTP method. Invoke a custom Apex REST method with an endpoint. Pass data to a custom Apex REST method by sending a request body in JSON format.
Where to find rest service data in apex?
The REST service data is displayed in an APEX report – on an APEX page You now can further configure your report details and layout. Of course, other Application Express components can also be used. If there is a DATE attribute in the REST service data, the Calendar component might be appropriate.
How to do the ” apex rest callouts ” trailhead?
The ‘getAnimalNameById’ method must call https://th-apex-http-callout.herokuapp.com/animals/:id, using the ID passed into the method. The method returns the value of the ‘name’ property (i.e., the animal name). Create a test class named AnimalLocatorTest that uses a mock class called AnimalLocatorMock to mock the callout response.
How to create an apex class and write a test?
To pass this challenge, create an Apex class that calls a REST endpoint to return the name of an animal, write unit tests that achieve 100% code coverage for the class using a mock response, and run your Apex tests. The Apex class must be called ‘AnimalLocator’, have a ‘getAnimalNameById’ method that accepts an Integer and returns a String.