generator-sails-rest-api icon indicating copy to clipboard operation
generator-sails-rest-api copied to clipboard

Implement JSON API spec

Open ghaiklor opened this issue 10 years ago • 8 comments
trafficstars

We can override blueprints for JSON API support.

ghaiklor avatar Oct 16 '15 15:10 ghaiklor

We have a common goal here. I may be able to help. I NEED a JSONAPI blueprint in a bad way. The entire Ember 2.X community does in fact. I am working with another developer who may be writing the serializer for this to work in Sails. I just turned his company on to your project. Cross your fingers. We may actually get this done. I will let you know. Have you already started on something or is this still in the, "not sure don't have time category"?

Cheers, Nichole

NikkiDreams avatar Jan 29 '16 02:01 NikkiDreams

@NikkiDreams thanks for help. We can integrate your JSON-spec compatible blueprints alongside with our current blueprints and allow to users choose which one they want to use. When you will be ready to create PR for this I'll be glad to do other stuff related to generator itself.

ghaiklor avatar Jan 29 '16 09:01 ghaiklor

I am starting to put stuff together. My project is stuck until JSON API support in Sails is available. Not sure if you have seen this https://github.com/IanVS/sails-hook-jsonapi I'm evaluating what was done at the moment.

NikkiDreams avatar Feb 02 '16 02:02 NikkiDreams

Ok. I know this is not ideal but it is a start. I forked the original sails-hook-jsonapi. My fork is basically working. There are many things that need/should get fixed though. This is only basics so far.

  • Smart handling of pluralization.
  • Add Blueprints
  • Add relationships support
  • Add links support
  • Add meta data support
  • Error Handling

Model and Collection relationships are pre loaded as you can see from my sample data queried from my users table.


  "data": [
    {
      "type": "users",
      "id": "1",
      "attributes": {
        "employer": [],
        "companies": [
          {
            "id": 1,
            "name": "Nikki's Magic Garden",
            "adminId": null,
            "industry": "Urban Farming",
            "address": "N Awesome St.",
            "addressSecondary": null,
            "city": "Portland",
            "state": "OR",
            "province": null,
            "postalCode": null,
            "countryCode": null,
            "details": {},
            "createdAt": "2016-02-01T23:49:15.000Z",
            "updatedAt": "2016-02-01T23:49:16.000Z"
          },
          {
            "id": 2,
            "name": "5Movez",
            "adminId": null,
            "industry": "Business Growth",
            "address": "SE Awesome St.",
            "addressSecondary": null,
            "city": "Portland",
            "state": "OR",
            "province": null,
            "postalCode": null,
            "countryCode": null,
            "details": {},
            "createdAt": "2016-02-01T23:49:15.000Z",
            "updatedAt": "2016-02-01T23:49:16.000Z"
          }
        ],
        "is-growth-champion": [],
        "growth-teams": [],
        "trios": [
          {
            "id": 1,
            "name": "Trio A",
            "team": 1,
            "workout": 1,
            "growthTeam": null,
            "growthChampion": null,
            "company": 1,
            "createdAt": "2016-02-01T23:49:15.000Z",
            "updatedAt": "2016-02-01T23:49:15.000Z"
          },
          {
            "id": 2,
            "name": "Trio A",
            "team": 1,
            "workout": 1,
            "growthTeam": null,
            "growthChampion": null,
            "company": 1,
            "createdAt": "2016-02-01T23:49:18.000Z",
            "updatedAt": "2016-02-01T23:49:18.000Z"
          },
          {
            "id": 3,
            "name": "Trio A",
            "team": 1,
            "workout": 1,
            "growthTeam": null,
            "growthChampion": null,
            "company": 1,
            "createdAt": "2016-02-01T23:49:35.000Z",
            "updatedAt": "2016-02-01T23:49:35.000Z"
          },
          {
            "id": 4,
            "name": "Trio A",
            "team": 1,
            "workout": 1,
            "growthTeam": null,
            "growthChampion": null,
            "company": 1,
            "createdAt": "2016-02-01T23:49:44.000Z",
            "updatedAt": "2016-02-01T23:49:44.000Z"
          }
        ],
        "workouts": [
          {
            "id": 1,
            "type": "access",
            "results": null,
            "complete": false,
            "active": true,
            "details": {},
            "createdAt": "2016-02-01T23:49:15.000Z",
            "updatedAt": "2016-02-01T23:49:16.000Z",
            "growthChampion": null,
            "growthteam": null,
            "company": 1,
            "worksheets": null
          },
          {
            "id": 2,
            "type": "access",
            "results": null,
            "complete": false,
            "active": true,
            "details": {},
            "createdAt": "2016-02-01T23:49:18.000Z",
            "updatedAt": "2016-02-01T23:49:19.000Z",
            "growthChampion": null,
            "growthteam": null,
            "company": 1,
            "worksheets": null
          },
          {
            "id": 3,
            "type": "access",
            "results": null,
            "complete": false,
            "active": true,
            "details": {},
            "createdAt": "2016-02-01T23:49:35.000Z",
            "updatedAt": "2016-02-01T23:49:36.000Z",
            "growthChampion": null,
            "growthteam": null,
            "company": 1,
            "worksheets": null
          },
          {
            "id": 4,
            "type": "access",
            "results": null,
            "complete": false,
            "active": true,
            "details": {},
            "createdAt": "2016-02-01T23:49:44.000Z",
            "updatedAt": "2016-02-01T23:49:45.000Z",
            "growthChampion": null,
            "growthteam": null,
            "company": 1,
            "worksheets": null
          }
        ],
        "username": "TheMaster",
        "email": "[email protected]",
        "first-name": "",
        "last-name": "",
        "photo": "",
        "phone": null,
        "postal-code": null,
        "details": {},
        "active": true,
        "admin-id": null,
        "created-at": "2016-02-01T23:49:16.000Z",
        "updated-at": "2016-02-01T23:49:16.000Z"
      }
    }
]

NikkiDreams avatar Feb 02 '16 05:02 NikkiDreams

@NikkiDreams do you think better to implement this in hooks ? I thought custom blueprints will be enough.

ghaiklor avatar Feb 02 '16 09:02 ghaiklor

Both have advantages. But I would prefer blueprints. In fact I think a combination may be useful. Since hooks was already 50% done I just edited it to get a start. My next stab at this will be blueprints and pulling the processin out of the OK response file. The OK response file is not the right way to call the serializer as it does now. But it's a start.

NikkiDreams avatar Feb 02 '16 10:02 NikkiDreams

@NikkiDreams it would be a great step forward when you implement JSON API :+1: Yeah, responses are a little different but we can use root parameter to override default response without modifying them.

ghaiklor avatar Feb 02 '16 12:02 ghaiklor

I just started the Blueprints part of this endeavor. I'm getting way to old to be pulling these all nighters. But someone's gotta do it right? This will hopefully be very flexible and probably everything you could possibly need when I get the jsonapi-serializer hooked up to the blueprint service. I have quite a lot to do here but I expect to have basic things working by end of the week. https://github.com/NikkiDreams/sails-generate-jsonapi-blueprints

sails-hook-jsonapi is now working. As a hook its super basic and not very flexible. But it does the job, mostly. It is a very basic, no frills alternative. https://github.com/NikkiDreams/sails-hook-jsonapi

Cheers

NikkiDreams avatar Feb 03 '16 10:02 NikkiDreams