mercredi 22 juillet 2015

providing granular data for data intensive web service

I am developing a webservice that is really data intensive. Unfortunately all of the data returned by it is not needed for all the calls, but might be needed for another call.

An overly simplified response might look something like below:

Response : {
    A,
    B,
    C,
    D : {
        X : {

        }
        y,
        z
    }
}

I want to provide flexibility to callers such that they can request for specific data from the big object. I thought of achieving it by exposing enums, and taking list of enum as input. Each enum map to a field in response.

example if caller needs only A and D, then they can specify it by passing list of enums like ImmutableList.of(GET_ENUM_A, GET_ENUM_D) And at web service end I can compute only A and D.

questions: Is there better way of taking input (other than enum) of what data is needed by caller?

I would like to give control to user over more fine grained data, eg. they can specify what part of D is needed. GET_ENUM_D_X.

At server end, I am thinking of implementing it using command pattern, having a command for each enum and executing it only if the corresponding enum is present in the list.

  • Here my D will be a facade.
  • If granular data is requested then don't use facade instead use command for X.

Issue I can think of:

  • I end up with too many commands.
  • If a command is a subset of another command and both are requested the execute only superset command (we need to do this in code)

Is there a better way of solving this problem.

(PS : I am not interested in fragmenting it to smaller APIs, because of certain use cases).

Aucun commentaire:

Enregistrer un commentaire