Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing time stamp value to REST API

Tags:

rest

I have a REST API which ends with /v2/users/ for corresponding url http://255.02.125.901:9087

How can I pass a timestamp to the API say, today morning 8 am, so that i can get all updates after it. Please The response will be json object.

Regards,

like image 219
boom Avatar asked Nov 22 '25 11:11

boom


2 Answers

Format the timestamp as ISO 8601:

{
    "timestamp": "2015-07-05T22:16:18Z"
}

Every programming language will have a function or library available to parse this format into a date/time object.

You specified that you want to retrieve all updates since a certain point in time. A timestamp is just some arbitrary metadata and should not be passed within the actual payload of the request. Furhtemore, as GET prevents entity bodies, you need to fallback to POST which removes the ability to cache the response and moreover has a completly different semantic than a retrieval! Therefore I highly recommend NOT sending the timestamp within a JSON body to the service.

Instead use a conditional GET request. This will also tell you that the timestamp to pass to the service will need to be in a format specified in Date and Time Specification section of RFC 2822.

If you don't want to use conditional GET requests, try passing the metadata with the URI f.e. like this:

/v2/users?year=2015&month=7&day=10&hour=11&minutes=9&seconds=10&timezone=CET

If you want you can allso encapsulate the timestamp within a path-parameter. Though, I would recomment using conditional get-requests

like image 40
Roman Vottner Avatar answered Nov 25 '25 10:11

Roman Vottner