Execute a PATCH call from an Extension by using AL and HttpClient

If you work with REST APIs, you already know that you’ve two HTTP methods for updating resources:

  • PUT: updates an entire resource
  • PATCH: the update request only needs to contain the changes to the resource, not the complete resource.

The AL language permits you to work with REST services by using the HttpClient class. If you declare an HttpClient object in AL, from Intellisense in Visual Studio Code you can see that you have the following methods for working with resources:

HTTPClientPatch_01.jpg

Where is Patch?? How can I perform a Patch REST call? Is this not supported?

The answer is no, the solution to perform a Patch request is just a bit hidden (don’t ask me why 🙂 ). Here is how you can send a Patch request to a REST resource from AL:

HTTPClientPatch_02.jpg

The key here is to add a PATCH method to the HttpRequestMessage object and then calling the Send method of HttpClient.

Easy and powerful 😉

 

1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.