0

For my use case I need to create a microservice that receives log messages through HTTP.

I'm wondering about the reasons to pick either of these:

Method: POST
URI: /{logLevel}/
Body: {
 "message": "..."
}
Method: POST
URI: /
Body: {
 "level": {either string or enum},
 "message": "..."
}

I feel like with the first method I can map each log level to an entirely different flow with ease and avoid validating the values by myself (the library does this using the predefined URIs).
But are there reasons to prefer the second method? What do you guys think?

0

There isn't a right or wrong way of doing this. It really depends on which approach makes sense for you given your context.

With that being said though :), I would go for solution 2 and send the log level inside the body. The reason is that you are dealing with one type of resource here, a LogMessage with two properties, the log level and the text message. It's more intuitive to send one type of resource to one base endpoint. In solution 1, you are sending one resource to many endpoints.

Another intuitive thing would be that, at some later moment, I'm expecting to see these log messages and inspect them to draw some conclusions about the process they are logging. Will you again think of creating different endpoints to retrieve different error levels? Or will you have only one endpoint that retrieves all types of log details? If you have one (and inevitabily you will need to provide one, because a client might want to see all logs from the past day no matter their severity, for example), in the results you will have to include the level property in the body of each LogMessage resource, so that your clients can differentiate between the severity of the messages.

So for these reasons, I would prefer solution 2, even though, as I said, there aren't any hard rules for how to implement this.

0

It's not entirely clear to me how you are storing the results here, but it appears as if you are storing the message and the logLevel separately.

If so, I would think about how this will look if you want to export the logs at some point later. How easy will it then be to extract logLevel? My initial hunch is that this would be easier if you use your second option.

On the other hand, perhaps one does not need to rule out the other; if applying the URL solution makes life easier, but you don't have any explicit reason to remove level from Body, then perhaps you could use both?:

Method: POST
URI: /{logLevel}/
Body: {
 "level": {either string or enum},
 "message": "..."
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.