Lets create a simple REST API to explore the concept:
- Navigate to System Web Services > Scripted Web Services > Scripted REST APIs and create a new record. Use these details, and Save.
- Name: Math
- In the Resources related list, click on New. Set the following fields:
- Name: Multiply
- HTTP method: get
- Relative path: /multiply/{a}/{b}
- Script: (Insert inside the provided function)
var body = {}; body.answer = request.pathParams.a * request.pathParams.b; response.setBody(body);
This very simple script looks at two input variables, multiplies them, and sends the response back.
- Once saved, click on Explore REST API. Give a numerical value for a and b, click on Send, and the instance will do ...