0

I am writing a service which would store picture associated with registered email. So, other domains would have a possibility to get image of the user by email. The main goal is not to upload it each time as nowadays we have to register almost everywhere and that process is quite annoying. My application is written on Java and I am using REST API. For example, user's account information is available by login:

    @RequestMapping(value = "/get/{login}",
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<User> getByEmail(@PathVariable String login) {
    User user = userDao.getUserByLogin(login);
    return Optional.ofNullable(user)
            .map(result -> new ResponseEntity<>(
                    result, HttpStatus.OK))
            .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}

And now, what i want is to send just updated data to the domains which gonna use my service. How could I figure that out? I think I could ask "domain" to provide some information in order to use my service (some king of registration), but what exactly should I ask for to be able to send data udpdates? In my thoughts they should also provide some REST path where I could send some kind of request that something has changed.

Any help would be appreciated a lot, thanks.

MWiesner
  • 8,868
  • 11
  • 36
  • 70
quento
  • 1,074
  • 4
  • 20
  • 43

2 Answers2

1

This is essentially a pub-sub model . You publish some information , on various defined events , to whoever has subscribed to it . Look at this as a subset of state syncronisation of the user information across various endpoints.

In your case , the 'domains' you are referring to would be subscribers of your service and the events could be 'itemAdded' , 'itemAdded' etc. You would want to 'push' out the updates ( or whole info) to the subscribers when the event they have subscribed for occurs , instead of them trying to pull this at some frequency ( that would be a lot of waste calls to your server - you dont want that ! )

There are various solutions available that could achieve this . The one I am going to point you to is called Twilio Sync . This would obviously mean that the 'domains' would have to do some changes at their end to subscribe and consume the updates , but I dont see how else could they be regularly updated if they want information pushed.

am1704
  • 837
  • 1
  • 6
  • 15
0
  • Send last update date to the endpoint from the domain which use it. Then check which data was updated after that date and return appropriate response.
  • Talking about image, you can always return URL for download but add last update field. The service which use REST service will determine to download it or not.

Also you may need event driven messaging, publish–subscribe pattern (https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern). Related threads:

Community
  • 1
  • 1
Justinas Jakavonis
  • 8,220
  • 10
  • 69
  • 114
  • could you provide an example please? Lets imagine that "domain" uses my API and get user's info by url "/user". Then the information has changed. WHERE should my service send new data or even any kind of response? As the "domain" knows about url to get user's information, but my service does not know anything about "domains" which uses it. So still the question, what should domain provide to have a possibility to change data? – quento Sep 13 '16 at 08:18
  • I don't understand your question completely. Is your aim to prevent downloading image every time? Are there any other cases? - I would return full user info for each request, no matter it changed or not. – Justinas Jakavonis Sep 13 '16 at 08:35
  • but what if user info is taken once and could be updated once get special notification? – quento Sep 13 '16 at 10:52
  • 1
    May be related http://stackoverflow.com/questions/1093900/how-would-i-create-an-asynchronous-notification-system-using-restful-web-service and http://stackoverflow.com/questions/568897/event-based-interaction-style-in-rest . For mobile app: https://firebase.google.com/docs/notifications/ – Justinas Jakavonis Sep 13 '16 at 10:58