json-api-php / json-api

Implementation of JSON API in PHP
https://json-api-php.github.io/
MIT License
183 stars 18 forks source link

Feedback Request #4

Closed f3ath closed 4 years ago

f3ath commented 7 years ago

Hi there! The goal of this library is to implement the business rules of JSON API Specification v1.0 in php 7. There are 2 main principles I want to follow.

I'd like to know what you think @tobscure @fesor @enleur @kefzce @sleepytomcat @franzliedke @crhayes

tobyzerner commented 7 years ago

Interesting project! Thoughts:

$author->setSelfLink('/articles/1/relationships/author');
// instead of
$author->setLink('self', '/articles/1/relationships/author');

Can the consumer be expected to know that the name of the self link is indeed 'self', or should it just know about a setSelfLink method? You've kind of done this with Document::setApiVersion and Document::setApiMeta. (Want to know your thoughts about this because it's relevant to tobscure/json-api too!)

f3ath commented 7 years ago

Thanks @tobscure I appreciate it a lot.

tobyzerner commented 7 years ago

I'm intrigued by this, I'm trying to think if there are any concepts I can steal and put back into tobscure/json-api :P

Thoughts on using Link objects vs. just passing $value and $meta to the setLink method?

Fair point re: getters.

How do you plan to implement compound documents?

f3ath commented 7 years ago

Feel free to use any of this. Initially I had Link and Meta, but refactored them out eventually. They can resurrect when I will be implementing attribute name validation though. Compounds are #1 in the list.

franzliedke commented 7 years ago

I too would be interested in the exact difference in scope between this (when it's done) and Toby's project. :)

f3ath commented 7 years ago

@franzliedke I don't know the answer. They might get pretty close. As I said, it was an attempt to rethink the object model for Toby's project. So far you can consider it an exercise in expressing the specification in pure TDD, I guess.

tobyzerner commented 7 years ago

@franzliedke I've been thinking about this a lot, here's the difference:

This library is simply a way to represent a known, valid JSON-API document structure in PHP.

tobscure/json-api has more utility: it takes raw data and transforms it into a JSON-API document structure.

I've just refactored some parts of tobscure/json-api to decouple the first part from the last part. If this library supported PHP 5.x, theoretically we could use it internally to do that last part of representing/validating the document. Alas, it's not a huge burden to implement that ourselves — I'm just happy to have cleaner code now :)

franzliedke commented 7 years ago

Sounds great, the decoupling makes sense.

And I've been searching for a library that does only the specification logic and serialization for a long time. (In Ruby, though, hehe.)

If this turns out to become the base of Toby's library one day, maybe we can turn that into something more opinionated for structuring an API, somewhat like a micro-framework for JSON-API endpoints.

f3ath commented 7 years ago

I have just release v1.0.0. It has BC breaking changes compared to v0.7. I would appreciate your feedback on it. Hey @johnrobertporter, as an early adopter, your feedback would be especially useful.

Thanks, guys.

ghost commented 7 years ago

As I'm close to an MVP, I will have to feedback after release; maybe in a month or so. Definitely happy to do so though.

f3ath commented 7 years ago

Thanks @johnrobertporter good luck with your project.