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 7842805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:24:23+00:00 2026-06-02T16:24:23+00:00

Suppose I have to implement game character resource. Character could have only one weapon.

  • 0

Suppose I have to implement game character resource. Character could have only one weapon.
Weapon types are different (sword, knife, gun etc.) and have different set of properties.
Character and Weapon are separate resources for sake of usability.
In OOP model it will looks as follows

enter image description here

What will be the best way to design URIs and resources for such structure?

edit:
In general. Is it ok to have in Character resource link to weapon resource that return Knife, Sword or Gun or it have to be the link to certain resource such as http:\game.com\character\sword?

  • 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-02T16:24:27+00:00Added an answer on June 2, 2026 at 4:24 pm

    In general, the REST model can be mapped directly as “Object” <-> “Representation” and “OID/References” <-> “URI”. So first, what you have to do is to assign each of the elements present in the game a different URI.

    Option 1

    Say you use JSON to describe the character, so you would have something like this:

    URL: /character/Warrior

    Content:

    { "name" : "Warrior", "weapon" : "/weapons/id_of_weapon" }
    

    Note how the “weapon” includes a link (or an array of those) to the different weapons that the character has. Each of those, following the REST principle, is identified by an URI.

    You have now two options to suport the type/subtype variation:

    Use different MIME types

    When you obtain the resource /weapons/id_of_weapon, you’ll get, say, a response from the server in which the headers look like this:

    HTTP/1.1 200 OK
    ...
    Content-Type: my-game/Knife
    ... (more headers)
    
    Knife data Content
    

    This identifies the actual type of the element returned, and can be used to map it to the different subtype. You can use different schemes, such as Weapon/Knife, or MyGameObject/Weapon_Knife.

    Use content-based object mapping

    Also, you can explicitly set the type of the returned instance. In this case, you could get a response like this:

    HTTP/1.1 200 OK
    ...
    Content-Type: application/json
    ... (more headers)
    
    { "type" : ["Weapon", "Knife"] , ... (rest of fields) }
    

    Note how the type JSON parameter is used as a standard in your game to specify the different types supported by that returned data.

    Option 2

    You may also consider, after your edit, that you can mimic the resource containment architectur in URIs. However, you propose http://whatever/character/sword. This is not appropriate, because you’re naming classes, and not resources. A more appropriate URL scheme would be something like:

    http://whatever/character/idc/weapon/idw
    

    where idc and idw are the identifiers of the character and the weapon respectively. Note that you don’t fix the exact type of the weapon in the resource URI (that is, you have to say weapon, not knife), but it may happen that actually the weapon with the id idw is actually of type Knife (using either of the options given above).

    If you map containment to URIs, you can also have a more compact format for the character as follows:

    { "id": "idc",
      "name" : "Warrior", 
      "weapon" : { "id": "idw", "type": "Knife", (rest of knife properties) }
    }
    

    Note how: each element has its own id. Containment is observed via JSON recursive object inclusion, you also specify the type of the weapon, and, still you can map the URL scheme just described to access the inner elements of the character.

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

Sidebar

Related Questions

I'm trying to implement java like url pattern matching in php. Suppose i have
Suppose you have a subsystem that does some kind of work. It could be
I have to implement charts in my application. Suppose i have a table structure
Suppose i have 5 window to be created in which one is parent and
Suppose I have class hierarchy like the one shown in picture. Suppose I need
Suppose I have two entities: User and UserGroup . They have a one-to-many relationship
Suppose I have a List<IMyInterface> ... I have three classes which implement IMyInterface :
Suppose you have to implement Graph class, containing some algorithms, using dfs (depth-first search).
Suppose I have a lot of math calculations which are quite tedious to implement
Let's suppose I have an interface named Controller. Several classes implement this interface and

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.