REST API PUT

0
I am getting into learning API:s, and find that the content for GET, POST and DELETE is sufficient, however when it gets to PUT and PATCH I am facing problems since I do not find examples among the existing videos and other content. As far as I have understood I can update an existing resource with PUT. If this recourse does not exist a new one will be created. As I find very little info how to even start, I will just attach what I have and the error I get. It is also likely that I need to start over since I am very uncertain where to start. I have a building with a unique BuildingNumber. The domain model for the whole project is below: Microflow for PUT method. Basically the only thing I know is that I need to publish it as a rest service but after that I am blank. Error that I currently get is an server error (500): Response body Download { "error": { "code": 500, "message": "An unexpected error occurred." } } Response headers content-length: 64 content-type: application/json;charset=utf-8 date: Tue,17 Aug 2021 14:47:42 GMT   Any sort of guiding on my learning path is appreciated.
asked
2 answers
2

So you need to debug your service. Set a breakpoint on 'import from JSON'-action, connect your debugger and try again.

It might also help to right-click that activity and 'Set errorhandling' to 'Custom without rollback' and add a logmessage-activity as error handler. now you can see your error.

Question: did you pass along the BuildingNumber (Buildning, hm I have seen that typo before in another question...) and in the import mapping, have you set that attribute as the key? Should look like this:

 

answered
1

Hi Ellen

I made you a simple example of a PUT-request: you want to update an existing ‘Person’ entity (with property FullName and Birthdate) or create the specific ‘Person’ if it doesn’t already exists.

To do so, go to your published REST service as is documented in here https://docs.mendix.com/howto/integration/expose-a-web-service

Microflow can look like this:

Run your application locally and then go to your root-url of your published REST service, you’ll find this here:

In Mendix, we use Swagger, so this will be the overview of your endpoints:

It’s the PUT we’re interested in:

Obviously, my birthdate isn’t today, it’s the 11th of April, should you be interested :)

Give it a go and press execute (for your own ease, create a person before hand with the fullname you wish and a specific birthdate, that’s what I did)

Give it a spin: press the execute button:

The logic was successfully executed, my birthdate has changed to today if I check the data overview:

Now, Ellen Pellosniemi is not in my database, let’s execute the PUT-request with this full name and the birthdate of 2000-01-01T00:00:00.000Z

Execute it:

Tadaa!

Hope this helps you!

Kind regards,

Leander

 

answered