bgmulinari / B1SLayer

A lightweight SAP Business One Service Layer client for .NET
MIT License
122 stars 42 forks source link

Response body with post request #48

Closed it-AhmedTaha closed 10 months ago

it-AhmedTaha commented 11 months ago

Hello, is there a way to get the response of successful post request and return it to the client? For example this request: await serviceLayer.Request("Invoices").PostAsync(arReserve); Typically, when performing a successful POST request, a response containing information about the created invoice is returned.

bgmulinari commented 10 months ago

Hi, @it-AhmedTaha. Yes, here's the example from the README.md:

// Performs a POST on /Orders with the provided object as the JSON body, 
// creating a new order and deserializing the created order in a custom model class
var createdOrder = await serviceLayer.Request("Orders").PostAsync<MyOrderModel>(myNewOrderObject);
trrytch commented 3 months ago

Hi @bgmulinari, I noticed that it's not possible to do the same for a Patch request, is there a way of knowing that the PatchAsync request was successful?

bgmulinari commented 3 months ago

@trrytch, PATCH requests don't have a return body. Since B1SLayer will throw in case of an error, you can simply use a try/catch to check if your request worked.