0

I am designing a RESTFUL API and I have a dude with one of my operations:

The client app needs to make a request to the server to retrieve a JSON with available questions to the user (based on certain restrictions).

The problem is that:

  • Every user belongs to a client, meaning that client only will see questions that belongs to client's users.

  • A priori, I don't know the id's of such questions.

  • A user can need a question that other user already have.

I have thought of using: v1/questions/next/{numberOfQuestions}

The numberOfQuestions parameters would be optional (1 by default) and the client will be got in server.

Which approach would be the better one?

Thanks!

Antonio Acevedo
  • 1,480
  • 3
  • 21
  • 39
  • What does `v1/questions/next/{numberOfEvents}` have to do with clients and users? –  Jun 11 '13 at 13:15
  • Sorry, It has some mistake on the text. I am newbie in RESTFul design but as far as I know, every url must match with a specific resource. Isn't it? So, If I have 'v1/questions/next/34', if 2 users of differents clients make this request, the response will be different. – Antonio Acevedo Jun 11 '13 at 13:22
  • No, the response *must* be the same. The URL must be enough to identify the resource. What do you want to achive? –  Jun 11 '13 at 13:22
  • I want to retrieve a collection of availabe questions from server but depending on the user's client, the set of questions inserted in the JSON will be different. Doesn't matter that? – Antonio Acevedo Jun 11 '13 at 13:25
  • Can the client be part of the URL? –  Jun 11 '13 at 13:30
  • I think so. Are yo saying something like v1/clients/{clientId}/questions/next/{numberOfQuestions} ? – Antonio Acevedo Jun 11 '13 at 13:32
  • Yes, something like this. What does the `next` stand for? –  Jun 11 '13 at 13:41
  • OK. The operation must have a param (next) to indicate the number of questions the client needs to retrieve. So i have to differenciate between access to question with id=3 and get next 3 questions (next/3) – Antonio Acevedo Jun 11 '13 at 13:46
  • Does a request to this URL including the `next` part always return the *same* response? –  Jun 11 '13 at 13:47
  • No. Must be the next 'n' availables so will be changing...what do you think will be the best approach? – Antonio Acevedo Jun 11 '13 at 13:49

1 Answers1

1

Get all questions for a user

GET /v1/clients/{clientId}/users/{userId}/questions

returns:

{"questions":
  [
    {
      "id": 1,
      "title": "What is brown and barks?",
      "answered": false
    },
    {
      "id": 1,
      "title": "What is brown and makes Moo?",
      "answered": false
    },
    {
      "id": 1,
      "title": "What is brown and makes Meow?",
      "answered": true
    }
  ]
}

Get only unanswered questions for a user

GET /v1/clients/{clientId}/users/{userId}/questions?answered=false

returns:

{"questions":
  [
    {
      "id": 1,
      "title": "What is brown and barks?",
      "answered": false
    },
    {
      "id": 1,
      "title": "What is brown and makes Moo?",
      "answered": false
    }
  ]
}

Get only one unanswered question for a user

GET /v1/clients/{clientId}/users/{userId}/questions?answered=false&limit=1

returns:

{"questions":
  [
    {
      "id": 1,
      "title": "What is brown and barks?",
      "answered": false
    }
  ]
}