0

Is it possible to return a code other than 200 OK from an ObjectReef operation.

context App::MyOperation: JsonObject
post:
    result = {
        name: 'Name',
        desc: 'Lorem ipsum'
    }

I noticed that the service always returns 200

curl http://localhost:1996/json/v001/app/MyOperation

how can I return another code like 404 or 500?

1 Answer 1

0

according to ObjectReef documentation it's always 200 OK (https://objectreef.dev/doc/rest-api-311/calling-operations-operation-call-) and the assumption is that you should not interfere with the returned HTTP status because it is at a lower level of abstraction.

The framework itself decides what status to return. Other than 200 code you can expect when, for example, the pre-condition is unfulfilled, there is an unauthorized attempt to access the API, or you are invoking a non-existent object. There can be plenty of reasons, but they are always at a slightly lower layer of abstraction than your code.

If you need to return some kind of status after performing your operation then, based on your example, simply add an additional field in the zwapped json

context App::MyOperation: JsonObject
post:
    result = {
        status: 'OK',
        name: 'Name',
        desc: 'Lorem ipsum'
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.