function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
seamas liseamas li 

Rest API request params is null when Testing

Hi Expert,

I am testing Rest Api Apex code:

@RestResource(urlMapping='/mytest/*')
global with sharing class salesforceRestCall{
    
    @HttpGet
    global static String doGet() { 
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
              
        system.debug(' RestContext.request.params :: '+  RestContext.request.params);        
        
        String phoneNumber=req.params.get('subscriptionId');

        String response = processRequest( phoneNumber);

        return response;
    }


Testing Apex class:

    static testMethod void getSubscriptionByPhoneNumberTest() {
    

        test.startTest();
        
        
        RestRequest req = new RestRequest();
        RestResponse res = new RestResponse();
        req.requestURI = '/services/apexrest/subscriptions?phoneNumber=416360999';
        req.httpMethod = 'GET';

        RestContext.request = req;
        RestContext.response= res;
        
        String susbscriptionDetail = salesforceRestCall.doGet();  
        test.stopTest();
    
    }

Why I can not get phoneNumber parameter?
Thank you so much.