How to send proper http response from web API?

External system calling appian web api with some json value. Now I have to put those data into database and send response accordingly.

Response code to send: 204 for success, 207 for partial success(eg. when 5 out of 10 records added successfully), 400 (bad gateway), 500, 502 and 504

 

How to configure it and test it in appian itself?

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    Hi  are there any specific reason behind overriding the default HTTP Status code?

    As you might be aware that, status 204 stands for "No content" where as  you want to return 204 for success. I agreed, http status 2xx indicates success but still each code indicates different statuses. E.g.

    200: OK

    201: Created

    202: Accepted

    203: Non-Authoritative Information

    204: No Content  etc...

    Generally when you are working with Web API then API takes care of the http responses e.g. (404, 500, 201, 200 etc..) however as per our requirement we can customise few responses (but not all, e.g. 404) by using a!httpResponse() function.

    Also, when you are persisting the data into the db using WEB API , I recommend using process model instead of smart service functions, because if it's a process, you will have better trace of the data and better control to debug the issues occued (if any).

Reply
  • 0
    Certified Lead Developer

    Hi  are there any specific reason behind overriding the default HTTP Status code?

    As you might be aware that, status 204 stands for "No content" where as  you want to return 204 for success. I agreed, http status 2xx indicates success but still each code indicates different statuses. E.g.

    200: OK

    201: Created

    202: Accepted

    203: Non-Authoritative Information

    204: No Content  etc...

    Generally when you are working with Web API then API takes care of the http responses e.g. (404, 500, 201, 200 etc..) however as per our requirement we can customise few responses (but not all, e.g. 404) by using a!httpResponse() function.

    Also, when you are persisting the data into the db using WEB API , I recommend using process model instead of smart service functions, because if it's a process, you will have better trace of the data and better control to debug the issues occued (if any).

Children