how can I expose the Sales force data as an Rest API so the external System can consume it. I was think if I can create a Apex Class like below-
@RestResource(urlMapping='/GetAccounts/*')
global with sharing class GetAccounts {
@HttpGet
global static Account doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account result = [SELECT Id, Name FROM Account WHERE Id = :accountId];
return result;
}
}
And for the external user to consume the data, I figured I could create a Connected App and give them the Username, Password, Consumer Key, and Consumer Secret, and they should be authenticating in Salesforce to acquire the URI and session ID. The API that is published above should be able to be called using the SessionID and URI. Is this the correct approach? Please let me know if there's anything I'm missing.
Is it feasible to utilise Swagger within the Apex Class, as there is a requirement to use Swagger with the API? Could you please explain how I may use Swagger with my API?