I have recently come across an unusual issue while incorporating Protobuf into my TypeScript frontend. My approach involves using Axios to communicate with my REST API and leveraging the protobuf.js library for handling Protobuf in the frontend. Since I am relatively new to working with Protobuf, I suspect that my lack of familiarity might be causing the problem.
The complication arises when I attempt to make multiple calls to the API with a specific payload.
For instance, let's say I intend to post three objects: object_1
, object_2
, and object_3
. As a result, I end up making three separate post requests. The initial request consistently processes correctly—object_1
successfully gets added to the backend. However, subsequent posts for object_2
and object_3
seem to retransmit object_1
instead. Upon examining this issue further, I discovered that my protobuf is getting appended to the existing payload. This results in the second request containing object_1
and
object_2</code}, while the third one includes <code>object_1
, object_2
, and object_3
. Consequently, the API only interprets the first protobuf (i.e., object_1
) and ends up adding object_1
three times.
In accordance with the documentation, here is how I am utilizing the protobuf.js package:
const message = Message.create({ message: 'hello' });
const buffer = Message.encode(message).finish();
await axios.post([...] message [...]);
Has anyone else faced a similar issue? Where could I possibly be going wrong?
Thank you!