Which is more efficient? Javascript OR Assign Message policy?

Is preparing a mock response in javascript is the efficient approach?
Actually, I have a scenario where I need to prepare a success and error mock response based on the query param.

Can anyone please suggest which approach is more efficient?
Approach 1. Using one javascript to prepare both success and error response.
Approach 2. Using two Assign Message policies each for success and error response.

Solved Solved
0 2 162
2 ACCEPTED SOLUTIONS

Not applicable

Apigee inbuilt polices are more efficient. So, I would suggest to use assign message policy over javascript.

View solution in original post

I suggest that you optimize for readability and maintainability, rather than for performance, at this point. You probably are not going to blow the performance budget one way or the other. Much more significant for performance will be things like I/O, service callouts, and so on.

As to readability, it may not be a huge difference one way or the other, and each team might be different. In my experience, AssignMessage is slightly more clear if my main goal is to assign something (headers, payload, etc) to a message object.

On the other hand sometimes you need some logic to figure out what to assign, or you need to loop through some data, and in that case of course JavaScript can be indispensable.

View solution in original post

2 REPLIES 2

Not applicable

Apigee inbuilt polices are more efficient. So, I would suggest to use assign message policy over javascript.

I suggest that you optimize for readability and maintainability, rather than for performance, at this point. You probably are not going to blow the performance budget one way or the other. Much more significant for performance will be things like I/O, service callouts, and so on.

As to readability, it may not be a huge difference one way or the other, and each team might be different. In my experience, AssignMessage is slightly more clear if my main goal is to assign something (headers, payload, etc) to a message object.

On the other hand sometimes you need some logic to figure out what to assign, or you need to loop through some data, and in that case of course JavaScript can be indispensable.