0

I need to build a /search API that allows someone to send a POST, and retrieve an ID that can be queried later via a seperate /results API.

I've looked at Spring methods:

DeferredResult

@Async

but neither seem to demonstrate returning an ID from a search. I need to have a system that can remember the ID and reference it when someone calls the /results API to retrieve specific results for a search.

Are there any examples of a Spring application doing this

Wayneio
  • 3,466
  • 7
  • 42
  • 73

1 Answers1

1

You must remember that Restful services are stateless, therefore It won't be a good practice keeping your search results states in the server.

One solution could be storing your search states on a Database (SQL/NoSQL) and using the Spring Cache support to improve response times.

When an user requests a new search using /search, on the server you must generate the ID, prepare your results and persist it on the database, then you send the new ID to the client. Later the client must request its results using /results/{searchId}.

Please let me know if you'll use this possible solution and I'll share you an example on Github

eHayik
  • 2,981
  • 1
  • 21
  • 33