Apex Framework / library for consuming REST servicesIs there a defacto 3rd party utilities library for Apex such as Apache Commons is for Java?Replicate Cross Object Formulas with Apex FrameworkApex Trigger Framework to handle old data and validationRegarding Rest Services using Rest ApiRe-trigger rest call if i get read time out error using apexApex REST API escaped quotesDisplaying Apex REST Callout issueApex rest HttpGet Method helpIs there a rest api that check the api calls limit without consuming an api call?Design pattern for an attachment trigger using trigger framework?

Arthur Somervell: 1000 Exercises - Meaning of this notation

What is the offset in a seaplane's hull?

Dragon forelimb placement

LaTeX closing $ signs makes cursor jump

Problem of parity - Can we draw a closed path made up of 20 line segments...

If I cast Expeditious Retreat, can I Dash as a bonus action on the same turn?

How do I create uniquely male characters?

Why don't electron-positron collisions release infinite energy?

What does it mean to describe someone as a butt steak?

What defenses are there against being summoned by the Gate spell?

Is it legal for company to use my work email to pretend I still work there?

Why do I get two different answers for this counting problem?

Fully-Firstable Anagram Sets

How to test if a transaction is standard without spending real money?

How to write a macro that is braces sensitive?

Service Entrance Breakers Rain Shield

Font hinting is lost in Chrome-like browsers (for some languages )

How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

What are the differences between the usage of 'it' and 'they'?

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

Mathematical cryptic clues

What is the word for reserving something for yourself before others do?

Are the number of citations and number of published articles the most important criteria for a tenure promotion?



Apex Framework / library for consuming REST services


Is there a defacto 3rd party utilities library for Apex such as Apache Commons is for Java?Replicate Cross Object Formulas with Apex FrameworkApex Trigger Framework to handle old data and validationRegarding Rest Services using Rest ApiRe-trigger rest call if i get read time out error using apexApex REST API escaped quotesDisplaying Apex REST Callout issueApex rest HttpGet Method helpIs there a rest api that check the api calls limit without consuming an api call?Design pattern for an attachment trigger using trigger framework?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















To consume REST services there is a lot of boilerplate code needed:



  1. Build Apex Objects to model the responses

  2. Code to deserialize REST responses to those classes

  3. Handling of HTTP requests, responses and errors

  4. ...

Did anyone come up with patterns or best practices codified into an open source library or framework that one could just reuse in a similar project without reinventing the callout-wheel over an over again?



Like the zillions of trigger-frameworks that exist as repos on Github...










share|improve this question




























    4















    To consume REST services there is a lot of boilerplate code needed:



    1. Build Apex Objects to model the responses

    2. Code to deserialize REST responses to those classes

    3. Handling of HTTP requests, responses and errors

    4. ...

    Did anyone come up with patterns or best practices codified into an open source library or framework that one could just reuse in a similar project without reinventing the callout-wheel over an over again?



    Like the zillions of trigger-frameworks that exist as repos on Github...










    share|improve this question
























      4












      4








      4


      2






      To consume REST services there is a lot of boilerplate code needed:



      1. Build Apex Objects to model the responses

      2. Code to deserialize REST responses to those classes

      3. Handling of HTTP requests, responses and errors

      4. ...

      Did anyone come up with patterns or best practices codified into an open source library or framework that one could just reuse in a similar project without reinventing the callout-wheel over an over again?



      Like the zillions of trigger-frameworks that exist as repos on Github...










      share|improve this question














      To consume REST services there is a lot of boilerplate code needed:



      1. Build Apex Objects to model the responses

      2. Code to deserialize REST responses to those classes

      3. Handling of HTTP requests, responses and errors

      4. ...

      Did anyone come up with patterns or best practices codified into an open source library or framework that one could just reuse in a similar project without reinventing the callout-wheel over an over again?



      Like the zillions of trigger-frameworks that exist as repos on Github...







      callout rest design-patterns libraries framework






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 3 at 19:17









      Robert SösemannRobert Sösemann

      13.2k1178225




      13.2k1178225




















          1 Answer
          1






          active

          oldest

          votes


















          6














          The ffhttp library should do the trick: https://github.com/financialforcedev/ffhttp-core



          It includes error handling, redirections, building header fields, oauth, mime attachments and more.



          EDIT - Sample code



          Say you want to consume the JSONPlaceholder /users rest resource.
          You could create a Named Credential for the URL.



          JSONPlaceholder named credential



          Then you can use ffhttp to make the request, handle the failure or successful response and deserialize into the intended format. FFHTTP only includes an OAuth client but it's pretty simple to create your own...



          public with sharing class ffhttpSample 

          /*
          * DTO for remote object result
          */
          private class RemoteUser
          Integer id;
          String name;
          String username;
          String email;


          /*
          * Vanilla HTTP request
          */
          public static RemoteUser[] getUsers()
          Http http = new Http();

          HttpRequest request = new HttpRequest();
          request.setEndpoint('callout:JSONPlaceholder/users');
          request.setMethod('GET');

          HttpResponse response = http.send(request);
          if (response.getStatusCode() == 200)
          return (RemoteUser[])JSON.deserialize(response.getBody(), List<RemoteUser>.class);
          else
          System.debug(response.getStatus());
          return new RemoteUser[];



          /*
          * FFHTTP request
          */
          public static RemoteUser[] getUsersFfhttp()
          SimpleClient client = new SimpleClient();
          client.setCredentials(new ffhttp_Client.NamedCredentials('JSONPlaceholder'));

          SimpleClientRequest request = new SimpleClientRequest(
          client,
          '/users',
          ffhttp_Client.REQUEST_METHOD_GET,
          new ffhttp_JsonDeserializer(List<RemoteUser>.class));

          // Execute and parse the response.
          // Alternatively you can use executeUnparsed() to return the response body as a String
          return (RemoteUser[])request.execute();


          /*
          * FFHTTP client implementations
          */
          private class SimpleClient extends ffhttp_Client.AbstractClient
          private class SimpleClientRequest extends ffhttp_Client.AbstractClientRequest
          SimpleClientRequest(IAbstractClient client, String endpoint, String requestMethod, ffhttp_IDeserialize deserializer)
          super(client, endpoint, requestMethod, null, deserializer);








          share|improve this answer

























          • Awesome. Actually a fully sufficient answer but I will leave it open to invite more people to share.

            – Robert Sösemann
            Apr 3 at 20:59











          • would you mind adding a few snippets intro your answer outlining how to use the library? How it handles certain aspects of REST consumption, de/serializing responses and such. I checked the repo and also the specific repos using this but its still somewhat hard to grasp the core concepts. But.. I have no doubt that it is like the fflib the best thing out there... (I would grant a big bounty to you for that in case you care about some SFSE points ;-)

            – Robert Sösemann
            2 days ago












          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "459"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f256451%2fapex-framework-library-for-consuming-rest-services%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          6














          The ffhttp library should do the trick: https://github.com/financialforcedev/ffhttp-core



          It includes error handling, redirections, building header fields, oauth, mime attachments and more.



          EDIT - Sample code



          Say you want to consume the JSONPlaceholder /users rest resource.
          You could create a Named Credential for the URL.



          JSONPlaceholder named credential



          Then you can use ffhttp to make the request, handle the failure or successful response and deserialize into the intended format. FFHTTP only includes an OAuth client but it's pretty simple to create your own...



          public with sharing class ffhttpSample 

          /*
          * DTO for remote object result
          */
          private class RemoteUser
          Integer id;
          String name;
          String username;
          String email;


          /*
          * Vanilla HTTP request
          */
          public static RemoteUser[] getUsers()
          Http http = new Http();

          HttpRequest request = new HttpRequest();
          request.setEndpoint('callout:JSONPlaceholder/users');
          request.setMethod('GET');

          HttpResponse response = http.send(request);
          if (response.getStatusCode() == 200)
          return (RemoteUser[])JSON.deserialize(response.getBody(), List<RemoteUser>.class);
          else
          System.debug(response.getStatus());
          return new RemoteUser[];



          /*
          * FFHTTP request
          */
          public static RemoteUser[] getUsersFfhttp()
          SimpleClient client = new SimpleClient();
          client.setCredentials(new ffhttp_Client.NamedCredentials('JSONPlaceholder'));

          SimpleClientRequest request = new SimpleClientRequest(
          client,
          '/users',
          ffhttp_Client.REQUEST_METHOD_GET,
          new ffhttp_JsonDeserializer(List<RemoteUser>.class));

          // Execute and parse the response.
          // Alternatively you can use executeUnparsed() to return the response body as a String
          return (RemoteUser[])request.execute();


          /*
          * FFHTTP client implementations
          */
          private class SimpleClient extends ffhttp_Client.AbstractClient
          private class SimpleClientRequest extends ffhttp_Client.AbstractClientRequest
          SimpleClientRequest(IAbstractClient client, String endpoint, String requestMethod, ffhttp_IDeserialize deserializer)
          super(client, endpoint, requestMethod, null, deserializer);








          share|improve this answer

























          • Awesome. Actually a fully sufficient answer but I will leave it open to invite more people to share.

            – Robert Sösemann
            Apr 3 at 20:59











          • would you mind adding a few snippets intro your answer outlining how to use the library? How it handles certain aspects of REST consumption, de/serializing responses and such. I checked the repo and also the specific repos using this but its still somewhat hard to grasp the core concepts. But.. I have no doubt that it is like the fflib the best thing out there... (I would grant a big bounty to you for that in case you care about some SFSE points ;-)

            – Robert Sösemann
            2 days ago
















          6














          The ffhttp library should do the trick: https://github.com/financialforcedev/ffhttp-core



          It includes error handling, redirections, building header fields, oauth, mime attachments and more.



          EDIT - Sample code



          Say you want to consume the JSONPlaceholder /users rest resource.
          You could create a Named Credential for the URL.



          JSONPlaceholder named credential



          Then you can use ffhttp to make the request, handle the failure or successful response and deserialize into the intended format. FFHTTP only includes an OAuth client but it's pretty simple to create your own...



          public with sharing class ffhttpSample 

          /*
          * DTO for remote object result
          */
          private class RemoteUser
          Integer id;
          String name;
          String username;
          String email;


          /*
          * Vanilla HTTP request
          */
          public static RemoteUser[] getUsers()
          Http http = new Http();

          HttpRequest request = new HttpRequest();
          request.setEndpoint('callout:JSONPlaceholder/users');
          request.setMethod('GET');

          HttpResponse response = http.send(request);
          if (response.getStatusCode() == 200)
          return (RemoteUser[])JSON.deserialize(response.getBody(), List<RemoteUser>.class);
          else
          System.debug(response.getStatus());
          return new RemoteUser[];



          /*
          * FFHTTP request
          */
          public static RemoteUser[] getUsersFfhttp()
          SimpleClient client = new SimpleClient();
          client.setCredentials(new ffhttp_Client.NamedCredentials('JSONPlaceholder'));

          SimpleClientRequest request = new SimpleClientRequest(
          client,
          '/users',
          ffhttp_Client.REQUEST_METHOD_GET,
          new ffhttp_JsonDeserializer(List<RemoteUser>.class));

          // Execute and parse the response.
          // Alternatively you can use executeUnparsed() to return the response body as a String
          return (RemoteUser[])request.execute();


          /*
          * FFHTTP client implementations
          */
          private class SimpleClient extends ffhttp_Client.AbstractClient
          private class SimpleClientRequest extends ffhttp_Client.AbstractClientRequest
          SimpleClientRequest(IAbstractClient client, String endpoint, String requestMethod, ffhttp_IDeserialize deserializer)
          super(client, endpoint, requestMethod, null, deserializer);








          share|improve this answer

























          • Awesome. Actually a fully sufficient answer but I will leave it open to invite more people to share.

            – Robert Sösemann
            Apr 3 at 20:59











          • would you mind adding a few snippets intro your answer outlining how to use the library? How it handles certain aspects of REST consumption, de/serializing responses and such. I checked the repo and also the specific repos using this but its still somewhat hard to grasp the core concepts. But.. I have no doubt that it is like the fflib the best thing out there... (I would grant a big bounty to you for that in case you care about some SFSE points ;-)

            – Robert Sösemann
            2 days ago














          6












          6








          6







          The ffhttp library should do the trick: https://github.com/financialforcedev/ffhttp-core



          It includes error handling, redirections, building header fields, oauth, mime attachments and more.



          EDIT - Sample code



          Say you want to consume the JSONPlaceholder /users rest resource.
          You could create a Named Credential for the URL.



          JSONPlaceholder named credential



          Then you can use ffhttp to make the request, handle the failure or successful response and deserialize into the intended format. FFHTTP only includes an OAuth client but it's pretty simple to create your own...



          public with sharing class ffhttpSample 

          /*
          * DTO for remote object result
          */
          private class RemoteUser
          Integer id;
          String name;
          String username;
          String email;


          /*
          * Vanilla HTTP request
          */
          public static RemoteUser[] getUsers()
          Http http = new Http();

          HttpRequest request = new HttpRequest();
          request.setEndpoint('callout:JSONPlaceholder/users');
          request.setMethod('GET');

          HttpResponse response = http.send(request);
          if (response.getStatusCode() == 200)
          return (RemoteUser[])JSON.deserialize(response.getBody(), List<RemoteUser>.class);
          else
          System.debug(response.getStatus());
          return new RemoteUser[];



          /*
          * FFHTTP request
          */
          public static RemoteUser[] getUsersFfhttp()
          SimpleClient client = new SimpleClient();
          client.setCredentials(new ffhttp_Client.NamedCredentials('JSONPlaceholder'));

          SimpleClientRequest request = new SimpleClientRequest(
          client,
          '/users',
          ffhttp_Client.REQUEST_METHOD_GET,
          new ffhttp_JsonDeserializer(List<RemoteUser>.class));

          // Execute and parse the response.
          // Alternatively you can use executeUnparsed() to return the response body as a String
          return (RemoteUser[])request.execute();


          /*
          * FFHTTP client implementations
          */
          private class SimpleClient extends ffhttp_Client.AbstractClient
          private class SimpleClientRequest extends ffhttp_Client.AbstractClientRequest
          SimpleClientRequest(IAbstractClient client, String endpoint, String requestMethod, ffhttp_IDeserialize deserializer)
          super(client, endpoint, requestMethod, null, deserializer);








          share|improve this answer















          The ffhttp library should do the trick: https://github.com/financialforcedev/ffhttp-core



          It includes error handling, redirections, building header fields, oauth, mime attachments and more.



          EDIT - Sample code



          Say you want to consume the JSONPlaceholder /users rest resource.
          You could create a Named Credential for the URL.



          JSONPlaceholder named credential



          Then you can use ffhttp to make the request, handle the failure or successful response and deserialize into the intended format. FFHTTP only includes an OAuth client but it's pretty simple to create your own...



          public with sharing class ffhttpSample 

          /*
          * DTO for remote object result
          */
          private class RemoteUser
          Integer id;
          String name;
          String username;
          String email;


          /*
          * Vanilla HTTP request
          */
          public static RemoteUser[] getUsers()
          Http http = new Http();

          HttpRequest request = new HttpRequest();
          request.setEndpoint('callout:JSONPlaceholder/users');
          request.setMethod('GET');

          HttpResponse response = http.send(request);
          if (response.getStatusCode() == 200)
          return (RemoteUser[])JSON.deserialize(response.getBody(), List<RemoteUser>.class);
          else
          System.debug(response.getStatus());
          return new RemoteUser[];



          /*
          * FFHTTP request
          */
          public static RemoteUser[] getUsersFfhttp()
          SimpleClient client = new SimpleClient();
          client.setCredentials(new ffhttp_Client.NamedCredentials('JSONPlaceholder'));

          SimpleClientRequest request = new SimpleClientRequest(
          client,
          '/users',
          ffhttp_Client.REQUEST_METHOD_GET,
          new ffhttp_JsonDeserializer(List<RemoteUser>.class));

          // Execute and parse the response.
          // Alternatively you can use executeUnparsed() to return the response body as a String
          return (RemoteUser[])request.execute();


          /*
          * FFHTTP client implementations
          */
          private class SimpleClient extends ffhttp_Client.AbstractClient
          private class SimpleClientRequest extends ffhttp_Client.AbstractClientRequest
          SimpleClientRequest(IAbstractClient client, String endpoint, String requestMethod, ffhttp_IDeserialize deserializer)
          super(client, endpoint, requestMethod, null, deserializer);









          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited yesterday

























          answered Apr 3 at 20:32









          frup42frup42

          21915




          21915












          • Awesome. Actually a fully sufficient answer but I will leave it open to invite more people to share.

            – Robert Sösemann
            Apr 3 at 20:59











          • would you mind adding a few snippets intro your answer outlining how to use the library? How it handles certain aspects of REST consumption, de/serializing responses and such. I checked the repo and also the specific repos using this but its still somewhat hard to grasp the core concepts. But.. I have no doubt that it is like the fflib the best thing out there... (I would grant a big bounty to you for that in case you care about some SFSE points ;-)

            – Robert Sösemann
            2 days ago


















          • Awesome. Actually a fully sufficient answer but I will leave it open to invite more people to share.

            – Robert Sösemann
            Apr 3 at 20:59











          • would you mind adding a few snippets intro your answer outlining how to use the library? How it handles certain aspects of REST consumption, de/serializing responses and such. I checked the repo and also the specific repos using this but its still somewhat hard to grasp the core concepts. But.. I have no doubt that it is like the fflib the best thing out there... (I would grant a big bounty to you for that in case you care about some SFSE points ;-)

            – Robert Sösemann
            2 days ago

















          Awesome. Actually a fully sufficient answer but I will leave it open to invite more people to share.

          – Robert Sösemann
          Apr 3 at 20:59





          Awesome. Actually a fully sufficient answer but I will leave it open to invite more people to share.

          – Robert Sösemann
          Apr 3 at 20:59













          would you mind adding a few snippets intro your answer outlining how to use the library? How it handles certain aspects of REST consumption, de/serializing responses and such. I checked the repo and also the specific repos using this but its still somewhat hard to grasp the core concepts. But.. I have no doubt that it is like the fflib the best thing out there... (I would grant a big bounty to you for that in case you care about some SFSE points ;-)

          – Robert Sösemann
          2 days ago






          would you mind adding a few snippets intro your answer outlining how to use the library? How it handles certain aspects of REST consumption, de/serializing responses and such. I checked the repo and also the specific repos using this but its still somewhat hard to grasp the core concepts. But.. I have no doubt that it is like the fflib the best thing out there... (I would grant a big bounty to you for that in case you care about some SFSE points ;-)

          – Robert Sösemann
          2 days ago


















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Salesforce Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f256451%2fapex-framework-library-for-consuming-rest-services%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Sum ergo cogito? 1 nng

          419 nièngy_Soadمي 19bal1.5o_g

          Queiggey Chernihivv 9NnOo i Zw X QqKk LpB