{"id":20806896,"url":"https://github.com/agentgill/http-framework","last_synced_at":"2026-03-11T19:01:44.387Z","repository":{"id":152507020,"uuid":"348981581","full_name":"agentgill/http-framework","owner":"agentgill","description":null,"archived":false,"fork":false,"pushed_at":"2021-03-18T07:34:20.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-18T13:38:23.980Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Apex","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/agentgill.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-18T07:34:00.000Z","updated_at":"2021-03-18T07:34:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"99766603-3d92-40f7-be2c-35ce9c5086fd","html_url":"https://github.com/agentgill/http-framework","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentgill%2Fhttp-framework","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentgill%2Fhttp-framework/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentgill%2Fhttp-framework/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agentgill%2Fhttp-framework/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agentgill","download_url":"https://codeload.github.com/agentgill/http-framework/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243152875,"owners_count":20244657,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T19:28:11.865Z","updated_at":"2026-03-11T19:01:44.347Z","avatar_url":"https://github.com/agentgill.png","language":"Apex","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTTPCalloutFramework\n\nHTTPCalloutFramework is a light weight framework for apex HTTP callouts in salesforce.\n\n## Overview\n\nHTTPCalloutFramework can be used to perform apex callouts to external systems. \nIt has in-built apex classes that can be used to perform HTTPCallouts. \nThe required information for the callout can be stored in the custom metadata named\n\n**HTTPCalloutConfiguration**.\nThe framework also consists of mock classes that can be used to define mocks for single\nand multiple HTTP Callouts in a single transaction. The code used in the framework is already covered\nso that you don't need to worry during the deployments.\n\n### Prerequisites\n\nThere are no such pre-requisites for installing and using this framework. \nIf you want to download the code in your local system, \nyou can do it by the executing the below command or downloading the code directly as a zip file.\n\n```bash\ngit clone https://github.com/rahulmalhotra/HTTPCalloutFramework.git\n```\n\n### Installing\n\nHTTPCalloutFramework is very easy to use. You can install this application in your salesforce org by using the **deploy to salesforce** button\npresent in the [deployment](#deployment) section of this readme. Installing this will add the following to your org :- \n\n1. HTTPCalloutService - Apex Class\n2. HTTPCalloutServiceMock - Apex Class\n3. HTTPCalloutServiceMultiMock - Apex Class\n4. HTTPCalloutFrameworkException - Apex Class\n5. HTTPCalloutServiceTest - Apex Class\n6. HTTPCalloutConfiguration - Custom Metadata\n7. TestMetadata - HTTPCalloutConfiguration record used in test class (should not be deleted)\n8. SFDCStopBlogs - HTTPCalloutConfiguration record (For demo purposes - can be deleted)\n9. HTTPCalloutConfiguration Layout - Layout for HTTPCalloutConfiguration metadata\n10. SFDCStopAPI - Remote Site Settings record for SFDC Stop API (For demo purposes - can be deleted)\n\n**HTTPCalloutFramework** is now ready for use.\n\n## Deployment\n\nYou can deploy HTTPCalloutFramework directly to your org by clicking the button below\n\n\u003ca href=\"https://githubsfdeploy.herokuapp.com?owner=rahulmalhotra\u0026repo=HTTPCalloutFramework\u0026ref=gsdt\"\u003e\n  \u003cimg alt=\"Deploy to Salesforce\"\n       src=\"https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png\"\u003e\n\u003c/a\u003e\n\nAn alternative way can be to use [SFDX Deploy Tool](https://github.com/rahulmalhotra/SFDX-Deploy-Tool) for deployment.\nFor that you can download the zip directly and rename it to unpackaged\nthat can be used by placing it inside the metadata folder of the application structure\n\n## Usage\n\n### Synchronous Callouts\n\nOnce installed you'll see the below custom metadata records created in your org:-\n\n![HTTPCalloutConfigurationMetadata](https://github.com/rahulmalhotra/HTTPCalloutFramework/blob/master/Images/HTTPCalloutConfigurationMetadata.JPG)\n\nYou'll have a SFDCStopBlogs metadata record along with a remote site setting record created for the same that you can use for testing the framework.\nYou can see that I have specified details of the request in the metadata itself.\n\n![SFDCStopBlogsMetadataRecord](https://github.com/rahulmalhotra/HTTPCalloutFramework/blob/master/Images/SFDCStopBlogsMetadataRecord.JPG)\n![SFDCStopAPIRemoteSiteSettingsRecord](https://github.com/rahulmalhotra/HTTPCalloutFramework/blob/master/Images/SFDCStopAPIRemoteSiteSettingsRecord.JPG)\n\nYou can copy and execute the below code in developer console to test the framework.\nAs you can see below, I have passed the custom metadata record developer name in the constructor.\nRest of the details are fetched automatically.\n\n```apex\nHttpCalloutService service = new HTTPCalloutService('SFDCStopBlogs');\nSystem.debug(service.getRequest());\nSystem.debug(service.sendRequest().getBody());\n```\n\n![DeveloperConsole](https://github.com/rahulmalhotra/HTTPCalloutFramework/blob/master/Images/DeveloperConsole.JPG)\n\nYou can check the logs once the code is executed and it should have the output as below\n\n![DeveloperConsoleLog](https://github.com/rahulmalhotra/HTTPCalloutFramework/blob/master/Images/DeveloperConsoleLog.JPG)\n\nCustom metadata and remote site setting record of SFDC Stop API are for demo purposes only. \nYou can delete these records after installation and create your own records for HTTP callouts.\nMake sure you **Do not delete the TestMetadata** record  of HTTPCalloutConfiguration custom metadata as it's being used in the test class for code coverage.\n\n### Asynchronous Callouts\n\nNow, let's jump on to the asynchronous apex callouts part. As you must be aware that the asynchronous callouts in apex are implemented using the [Continuation](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Continuation.htm) class. The continuation class has different syntax for Visualforce Pages and Lightning Components. So, we're going to see the syntax for implementation in both cases. The good thing is that we have a single [HTTPCalloutAsyncService](https://github.com/rahulmalhotra/HTTPCalloutFramework/blob/master/classes/HTTPCalloutAsyncService.cls) class that we can use for both Visualforce Pages and Lightning Components.\n\n#### Visualforce Page\n\nThe syntax of vf page controller is given below:-\n\n```apex\nHTTPCalloutAsyncService service {get;set;} // Creating an instance of HTTPCalloutAsyncService in controller\nList\u003cString\u003e requestLabels; // This list will be used to store the request labels returned by the continuation process\n// Define your action method (should have return type of Object)\npublic Object sendAsyncCalloutRequest() {\n    service = new HTTPCalloutAsyncService(\u003cInteger Timeout\u003e, new List\u003cString\u003e {\u003cCustomMetadata1\u003e, \u003cCustomMetadata2\u003e, \u003cCustomMetadata3\u003e});       \n    Continuation con = service.sendRequest('getAsyncCalloutResponse'); // Pass the callback method name in the parameter\n    requestLabels = service.getRequestLabels(); // Storing the request labels returned by continuation\n    return con; // Returning the continuation\n}\n\n// Define a callback method with the same name as passed in the sendRequest method of service class\npublic Object getAsyncCalloutResponse() {\n    // Getting a list of responses by passing the request labels in the parameter\n    List\u003cHTTPResponse\u003e responses = service.getResponse(requestLabels);\n    // Process the responses (Set variables that are being used in VF Page)\n    // Returning null to re-render the vf page\n    return null;\n}\n```\n\nThe visualforce page should have an command button calling our controller method as shown below:-\n```html\n\u003capex:commandButton action=\"{!sendAsyncCalloutRequest}\" value=\"Send Request\"  reRender=\"\u003cid of the block to re render\u003e\"/\u003e\n```\n\n#### Lightning Component\n\nThe syntax of lightning component controller is given below:-\n\n```apex\n// This method will be called from lightning component (should have return type of Object)\n@AuraEnabled(cacheable=true continuation=true)\npublic static Object fetchData() {\n    HTTPCalloutAsyncService service = new HTTPCalloutAsyncService(\u003cInteger Timeout\u003e, new List\u003cString\u003e {\u003cCustomMetadata1\u003e, \u003cCustomMetadata2\u003e, \u003cCustomMetadata3\u003e});\n    return service.sendRequest('sendResponse'); // Pass the response method name in the parameter\n}\n\n// Define a callback method with the same name as passed in the sendRequest method of service class\n@AuraEnabled(cacheable=true)\npublic static Object sendResponse(List\u003cString\u003e labels, Object state) {\n    HTTPCalloutAsyncService service = new HTTPCalloutAsyncService(\u003cInteger Timeout\u003e, new List\u003cString\u003e {\u003cCustomMetadata1\u003e, \u003cCustomMetadata2\u003e, \u003cCustomMetadata3\u003e});\n    // Getting a list of responses by passing the request labels in the parameter\n    List\u003cHTTPResponse\u003e responses = service.getResponse(labels);\n    // Process the responses (Create a wrapper to send the response)\n    // Returning the wrapper in JSON format back to lightning component\n    return JSON.serialize(\u003cwrapper\u003e);\n}\n```\n\nWe should have call our apex method in lightning component helper as shown below:-\n```js\nvar fetchDataAction = component.get('c.fetchData');\nfetchDataAction.setCallback(this, function(response) {\n  if(response.getState() === 'SUCCESS') {\n    var data = JSON.parse(response.getReturnValue());\n  }\n}\n$A.enqueueAction(fetchDataAction);\n```\n\nI have created a working example for both VF and Lightning that you can deploy in your org by clicking the below button. **Make sure that you've installed the framework in your org first otherwise the deployment of examples will fail.**\n\n\u003ca href=\"https://githubsfdeploy.herokuapp.com?owner=rahulmalhotra\u0026repo=HTTPCalloutFramework\u0026ref=asyncexample\"\u003e\n  \u003cimg alt=\"Deploy Asynchronous Examples to Salesforce\"\n       src=\"https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png\"\u003e\n\u003c/a\u003e\n\nThe working example consist of a VF Page named **SFDCStopCallout** and a Lightning Application named **BlogsContinuationApp** that will make an asynchronous continuation call to SFDC Stop APIs and fetch the data using our framework.\n\n*Visualforce Page Output :-*\n\n![SFDCStopCalloutVFPage](https://github.com/rahulmalhotra/HTTPCalloutFramework/blob/master/Images/SFDCStopCalloutVFPage.JPG)\n\n*Lightning Component Output :-*\n\n![BlogsContinuationApp](https://github.com/rahulmalhotra/HTTPCalloutFramework/blob/master/Images/BlogsContinuationApp.JPG)\n\n## Tools and Softwares used\n\nYou just need a salesforce org to run this application. \nIf you want to make any changes in the code, you can do that by using the developer console provided by Salesforce. \nHowever I like to use VS Code IDE to keep a local copy of code on my system too. For regular deployments, \nI use SFDX Deploy Tool. So below are the tools or softwares I use personally :-\n\n* [VS Code](https://code.visualstudio.com) - Open Source IDE for Salesforce\n* [SFDX Deploy Tool](https://github.com/rahulmalhotra/SFDX-Deploy-Tool) - SFDX Deploy Tool for Windows\n\n## Todo\n\n- [ ] Find a way to cover code adding client certificate to HTTP callout in test class. \nIt will increase the code coverage of HTTPCalloutService class to 100% (Current coverage:- 99%)\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for details on code of conduct and the process for submitting pull requests.\n\n## Authors\n\n* **Rahul Malhotra** - [@rahulcoder](https://twitter.com/rahulcoder)\n\n## License\n\nThis project is licensed under the BSD 3-Clause License - see the [LICENSE.md](LICENSE.md) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentgill%2Fhttp-framework","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagentgill%2Fhttp-framework","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagentgill%2Fhttp-framework/lists"}