Handling Int64 in API Proxy

Hi everyone,

I need to convert int to int64 in the api proxy.

AFAIK, int64 is not supported in javascript by default, therefore a workaround is needed for this case.

Does anyone know what's the best practice to handle int64?

0 3 424
3 REPLIES 3

More details please. More context.

Proxies deal with HTTP messages, which have headers containing strings, and payloads that are streams of bytes.

There is no "int64".

What are you really trying to do?

Here is the explanation,

Apigee get incoming request and send it to backend.

Then Backend send the response to Apigee with JSON Payload.

The JSON payload itself then transformed in the Apigee using javascript policy.

One of the field in the payload contain integer. But, the client who sent the request expect int64 format the payload response.

This case expected to be handled by Apigee. The reason is simple, make simple changes in the backend that handle more than 30 million active subscriber have some risks and takes time.

Hopefully that explanation is enough to understand.

The JSON payload itself then transformed in the Apigee using javascript policy.

One of the field in the payload contain integer. But, the client who sent the request expect int64 format the payload response.

I believe the problem is not Apigee Edge. The problem is JavaScript. If you modify a JSON payload within a JavaScript module, ... calling JSON.parse() and then JSON.serialize(), then you will cause a rounding to occur for any integers above a certain value.

I explained this in a separate answer to a different question a few days ago.

To avoid the loss of precision, don't parse and re-serialize the JSON from within a plain JavaScript module. If you DO need to re-shape the response payload, you may want to try:

  • use Java.
  • use json-bigint within a hosted target to run a node process that parses/stringifies JSON without losing precision. This won't work within a JS callout unless you browserify it.