How to you send a success message


#1

How do you send a success message in the api?

For example, lets say you have a logout endpoint in your api.

If an error occurs the output would be something like this:

{
    errors: [{
        "status": "401",
        "title": "Unauthorized",
        "detail": "Invalid credentials"
    }]
}

How do you send a success message, saying congratulations you have logged in.

Do you add it to the data object:

{  
    "data":{  
        "type":"success",
        "attributes":{  
            "info":{  
                "title":"success",
                "message":"Congrats for logging in.",
                "status":"200"
            }
        }
    }
}

Or do you add it to the meta object:

{  
    "meta":{  
        "success":{  
            "title":"success",
            "message":"Congrats for logging in.",
            "status":"200"
        }
    }
}

#2

Is your goal here just to communicate success, or to deliver a particular user-facing message? If it’s just to communicate success, then you really don’t need to send anything back… You can just respond with a 204 No Content status. If you need to communicate a particular message, it probably makes the most sense to put that message in meta, though, depending on what the request looks like to trigger the login, puting it in data might also be appropriate


#3

yes i wanted to send a user-facing message. I found this post: token message, I decided to go with the data attribute approach. Thank you for your help.