SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
805 stars 171 forks source link

Return a long in the response after a POST #163

Closed Skyark112 closed 7 years ago

Skyark112 commented 7 years ago

Hey there,

So due to some political reasons within my project, we need to be able to return a serialize_id and pass that as part of the response object after performing a successful POST request.

Is there a way to easily modify the response object that gets returned back after a POST request?

For example a POST response would generate something like HTTP/1.1 201 Created Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: * Access-Control-Expose-Headers: Location, ETag, Auth-Token, Auth-Token-Valid-Until, Auth-Token-Location, X-Powered-By Connection: keep-alive Content-Length: 0 Date: Tue, 08 Mar 2016 13:26:06 GMT ETag: 56ded2ee2d174c2a08cdee85 Location: http://127.0.0.1:8080/db/coll/56ded2eead66b2a1e741c054 X-Powered-By: restheart.org

I was wondering if it i's possible to add something like "Serialize_ID: xxxxxxxxxxxxxxx" to this response.

I do realize that you give us the "etag" and the location of the document in mongo, but we can't use the ObjectIDs in our current system, we have to use a long type.

ujibang commented 7 years ago

Hi @Skyark112

if you just need to have the _id of type long, then you can generate it client side and include in the request:

POST { "_id": 137, .... }
or
POST { "_id": {"$numberLong": "23423324" }, .... }

see $numberLong

will create documents with _id=137 or _id=23423324

If you rather want to transform the response and add some data (such as Serialize_ID) via a representation transformer, this is not yet available for write requests, but it is planned for 3.0. see task extend response transformers to write request in our backlog

Skyark112 commented 7 years ago

@ujibang

Thanks you for the response! I wanted to do something like your second suggestion, but in the end we managed to convince the other party to pass in their own long type id - like your first suggestion haha. I don't think we want to move to 3.0.0 yet, but once you have a stable release of that I hope to upgrade!

ujibang commented 7 years ago

please close this one and open a new issue. it will help others to find a solution for similar problems....