Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8287497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:03:48+00:00 2026-06-08T12:03:48+00:00

Question How do I return different results for the same resource? Details I have

  • 0

Question

How do I return different results for the same resource?

Details

I have been searching for some time now about the proper way to build a RESTful API. Tons of great information out there. Now I am actually trying to apply this to my website and have run into a few snags. I found a few suggestions that said to base the resources on your database as a starting point, considering your database should be structured decently. Here is my scenario:

My Site:

Here is a little information about my website and the purpose of the API

We are creating a site that allows people to play games. The API is supposed to allow other developers to build their own games and use our backend to collect user information and store it.

Scenario 1:

We have a players database that stores all player data. A developer needs to select this data based on either a user_id (person who owns the player data) or a game_id (the game that collected the data).

Resource

http://site.com/api/players

Issue:

If the developer calls my resource using GET they will receive a list of players. Since there are multiple developers using this system they must specify some ID by which to select all the players. This is where I find a problem. I want the developer to be able to specify two kinds of ID’s. They can select all players by user_id or by game_id.

  1. How do you handle this?
  2. Do I need two separate resources?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:03:49+00:00Added an answer on June 8, 2026 at 12:03 pm

    Lets say you have a controller name ‘Players’, then you’ll have 2 methods:

    function user_get(){
       //get id from request and do something
    }
    
    function game_get(){
    //get id from request and do something
    }
    

    now the url will look like: http://site.com/api/players/user/333, http://site.com/api/players/game/333

    1. player is the controller.
    2. user/game are the action

    If you use phil sturgeon’s framework, you’ll do that but the url will look like:
    http://site.com/api/players/user/id/333, http://site.com/api/players/game/id/333

    and then you get the id using : $this->get('id');

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Bit of a strange question. I have a website which has some pages in
I have been trying to get the crc32 function from PHP to match results
I have a pretty basic query, but I'd like it to return the results
Important : Please see this very much related question: Return multiple values in C++
Question: How would one write a function to check and return whether or not
My question is very much like Getting the return value of a PL/SQL function
Question: I'm using eval to parse a JSON return value from one of my
My question is how can I return a nil from an exception instead of
This question seems to suggest that Ajax requests are not guaranteed to return in
First question on Stackoverflow (.Net 2.0): So I am trying to return an XML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.