Search code examples
api-designdirectus

API Structure for an application


I would like some help to build something a la https://pokeapi.co/ .

I have a problem when I try to make the following structure:

"forms": [
        {
            "url": "https://pokeapi.co/api/v2/pokemon-form/1/",
            "name": "bulbasaur"
        }
    ],
"stats": [
    {
        "stat": {
            "url": "https://pokeapi.co/api/v2/stat/6/",
            "name": "speed"
        },
        "effort": 0,
        "base_stat": 45
    },
]

Directus works fine when I have one relation field such as forms (make a new relation field to forms, get Bulbasaur, done)

I would have build monster and the stat table, and I need to give a value to the relation field stat (in that case, speed) of 45.

I tried to fiddle around with Directus with no success.


Solution

  • Hey André – it seems like this is more of a database architecture question. But here is a schema I would use:

    • monsters
      • id
      • name
      • stats (ALIAS: Many-to-Many interface relationship)
    • monster_stats (Junction table for the many-to-many)

      • id
      • monster_id
      • stat_id
    • stats

      • id
      • name
      • effort
      • base_stat