andersondanilo / jsonapi-fractal Goto Github PK
View Code? Open in Web Editor NEWJSON:API Serializer inspired by Fractal (PHP)
License: MIT License
JSON:API Serializer inspired by Fractal (PHP)
License: MIT License
Thank you for starting this!
It is listed at https://jsonapi.org/implementations/#server-libraries-node-js but as the type definition of serialize
say it returns null
I wonder if this is in any shape to be used?
So support for these kind of serialization libraries has died down quite a bit. Moreover, all of them fail to serialize the entire spec...
So over the past few days I've designed a resource-recursive, typescript/javascript library for serializing the entire JSON:API spec. Our API is far more fluent (and obvious) than the one here (and every other serializer I have seen/used). If this serializer doesn't fit your need, you might want to check it out :) Development is active.
If you are in particular struggling with issues such as links, resource relationships, and deep recursion (essentially any of the complicated parts of the JSON:API spec), I strongly recommend moving to our library.
{TS:JAPI}: https://github.com/jun-sheaf/ts-japi
For example, a new user is about to be created and the role is being referenced. The problem is that in the result of serialization the relationship type is singular ("role"), not plural ("roles").
import { serialize } from 'jsonapi-fractal';
const user = {
name: 'Jon Snow',
role: { id: 123 }
};
const jsonApiFormatted = serialize(user, 'users', { relationships: ['role'] });
console.log(JSON.stringify(jsonApiFormatted));
outputs:
{
"data": {
"type": "users",
"attributes": {
"name": "Jon Snow"
},
"relationships": {
"role": {
"data": {
"type": "role",
"id": 123
}
}
}
}
}
jsonapi-fractal/src/serializer.ts
Line 13 in 580b7fb
Dear @andersondanilo ,
this library seems really easy to use. However, i noticed, that there are several features from json:api missing - for example, errors. Or features are broken, like the options.fields
attribute, ...
Are you planning to maintain this library?
All the best,
Johannes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.