Tuesday, March 8, 2016

Developer:Integration: Testing REST API using workbench.

So, you built a REST API integration, wrote a test class to validate your code and everything seems to be fine with the test results and code coverage.

How do you test your code and actually see it generate the desired output?

Solution

Workbench.developerforce.com is a tool that can be used to test your API's.
Log in to the desired environment.

Click on Utilities---REST explorer.

Select the method for which you have built your API. For our purpose I am going to assume it is a GET method that was written.

So, select the HTTP method as GET and in the URL:

after entering /services/apexrest/

enter the name of the RESTResource (url mapping) as defined in the global class.

Let's call it CheckReq. Your URL should now look as follows:

/services/apexrest/CheckReq

Say within the global API you have a class called CheckReqProcessing then your URL should finally look like:

/services/apexrest/CheckReq/CheckReqProcessing; hit execute.

Get Method does not require an input so you should see the results of your API.
Your class code would be looking something like:

@RestResource(urlMapping='/CheckReq/*')

global with sharing class CheckReqProcessing {

@HttpGet
<<<Define Actions>>>>

}

Test Class Code:

Your test class code would need to have the following amongst all the all the things that it needs to be successfull:

RestRequest req = new RestRequest();

        RestResponse res = new RestResponse();
        req.requestURI = '/services/apexrest/CheckReq';
        req.httpMethod = 'GET';
        RestContext.request = req;
        RestContext.response = res;
        
        List<ObjjectName> CR = CheckReqProcessing.getUnsentCR();

12 comments:

  1. A nice article here, i think that people who have grown up with the idea of using computers are showing more responsibility towards writing posts that are thoughtful, do not have grammar mistakes and pertinent to the post..

    Salesforce Training in Chennai


    AWS Training in Chennai

    ReplyDelete

  2. Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
    rpa training in bangalore
    best rpa training in bangalore
    RPA training in bangalore
    rpa course in bangalore
    rpa training in chennai
    rpa online training

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
    python interview questions and answers
    python tutorials
    python course institute in electronic city

    ReplyDelete
  5.   Your new valuable key points imply much a person like me and extremely more to my office workers. With thanks; from every one of us.
    python interview questions and answers
    python tutorials
    python course institute in electronic city

    ReplyDelete

  6. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

    AWS TRAINING IN BTM LAYOUT | AWS TRAINING IN BANGALORE
    AWS Training in Marathahalli | AWS Training in Bangalore

    ReplyDelete

  7. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

    AWS TRAINING IN BTM LAYOUT | AWS TRAINING IN BANGALORE
    AWS Training in Marathahalli | AWS Training in Bangalore

    ReplyDelete
  8. Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative.keep sharing!!!

    Android Training in Chennai

    Android Online Training in Chennai

    Android Training in Bangalore

    Android Training in Hyderabad

    Android Training in Coimbatore

    Android Training

    Android Online Training

    ReplyDelete