Skip to content
Snippets Groups Projects
Solid-introduction.rst 7.23 KiB

SOLID is a standard that universalizes API

SOLID is a project start in 2015 and lead in the 3WC by Tim Berners Lee, the inventor of the web. He was upset that his warning about the future of the web wasn’t heard and that’s why he propose a new way to build web application that give power back to the final user.

SOLID project has inspired Startin’blox a lot. This is the way we implement SOLID specifications.

Here is an example of our API :

{
    "@id": "https://api.alpha.happy-dev.fr/users/alice/",
    "first_name": "Alice",
    "last_name": "Poggioli",
    "username": "alice",
    "email": "alice.poggioli@paca.happy-dev.fr",
    "account": {
        "@id": "https://api.alpha.happy-dev.fr/accounts/alice/"
    },
    "name": "Alice Poggioli",
    "profile": {
        "@id": "https://api.alpha.happy-dev.fr/profiles/alice/"
    },
    "circles": {
        "@id": "https://api.alpha.happy-dev.fr/users/alice/circles/",
        "@type": "ldp:Container",
        "ldp:contains": [
            {
                "@id": "https://api.alpha.happy-dev.fr/circle-members/23/"
            },
            {
                "@id": "https://api.alpha.happy-dev.fr/circle-members/54/"
            },
            {
                "@id": "https://api.alpha.happy-dev.fr/circle-members/656/"
            }
        ],
        "permissions": [
            {
                "mode": {
                    "@type": "add"
                }
            },
            {
                "mode": {
                    "@type": "view"
                }
            }
        ]
    },
    "@type": "foaf:user",
    "@context": [
        "https://cdn.happy-dev.fr/owl/hdcontext.jsonld",
        {
            "get_full_name": "rdfs:label"
        }
    ],
}

Looks like a simple JSON but it’s more

Did you notice the presence of a context ?

{
   "@type": "foaf:user",
   "@context": [
       "https://cdn.happy-dev.fr/owl/hdcontext.jsonld",
       {
           "get_full_name": "rdfs:label"
       }
   ]
}

It is a way to go from the Json to JsonLD

That’s mean that we encode Linked Data using Json.

JsonLD is an RDF implementation, which is its-selft the basic language of semantic web.

This context allows you to link object properties in a JSON document to concepts in an ontology.

Here is the context referred :

{
  "@context": {
    "@vocab": "http://happy-dev.fr/owl/#",
    "foaf": "http://xmlns.com/foaf/0.1/",
    "doap": "http://usefulinc.com/ns/doap#",
    "ldp": "http://www.w3.org/ns/ldp#",
    "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
    "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "xsd": "http://www.w3.org/2001/XMLSchema#",
    "geo": "http://www.w3.org/2003/01/geo/wgs84_pos#",
    "acl": "http://www.w3.org/ns/auth/acl#",
    "name": "rdfs:label",
    "deadline": "xsd:dateTime",
    "lat": "geo:lat",
    "lng": "geo:long",
    "jabberID": "foaf:jabberID",
    "permissions": "acl:accessControl",
    "mode": "acl:mode",
    "view": "acl:Read",
    "change": "acl:Write",
    "add": "acl:Append",
    "delete": "acl:Delete",
    "control": "acl:Control"
  }
}

The type we use is foaf. That means that we use the FOAF ontology which is done to describe people.

If you go to the foaf ontology, you’ll see that the properties which we can use are :

account | accountName | accountServiceHomepage | age | aimChatID | based_near | birthday | currentProject | depiction | depicts | dnaChecksum | familyName | family_name | firstName | focus | fundedBy | geekcode | gender | givenName | givenname | holdsAccount | homepage | icqChatID | img | interest | isPrimaryTopicOf | jabberID | knows | lastName | logo | made | maker | mbox | mbox_sha1sum | member | membershipClass | msnChatID | myersBriggs | name | nick | openid | page | pastProject | phone | plan | primaryTopic | publications | schoolHomepage | sha1 | skypeID | status | surname | theme | thumbnail | tipjar | title | topic | topic_interest | weblog | workInfoHomepage | workplaceHomepage | yahooChatID |

Now we can describe a user for every machines in the world using a universal language :)

Why JsonLD is awesome ?

A document structured in RDF is a set of triplets.

An RDF triplet is an association (subject, predicate, object) :

  • the “subject” represents the resource to be described;
  • the “predicate” represents a type of property applicable to this resource;
  • the “object” represents a data or another resource: it is the value of the property.

But in today life, we use to structure datas in in a file, directory, inventory logic and not in linked triplets. It’s quickly a mess to apprehend.

JsonLD allow us to us Linked Datas in a very intuitive way.

That’s the time to speak about containers

So how JsonLD manage to tiny the datas ?

Let’s have a look on this part :

{
    "circles": {
        "@id": "https://api.alpha.happy-dev.fr/users/alice/circles/",
        "@type": "ldp:Container",
        "ldp:contains": [
            {
                "@id": "https://api.alpha.happy-dev.fr/circle-members/23/"
            },
            {
                "@id": "https://api.alpha.happy-dev.fr/circle-members/54/"
            },
            {
                "@id": "https://api.alpha.happy-dev.fr/circle-members/656/"
            }
        ],
        "permissions": [
            {
                "mode": {
                    "@type": "add"
                }
            },
            {
                "mode": {
                    "@type": "view"
                }
            }
        ]
    }
}

In web semantic language, that’s mean :

The resource pointed by the uri “https://api.alpha.happy-dev.fr/users/alice/circles/” virtually contains thoses resources.

With this trick, we stay in a semantic logic with a directory and file structuring management.

LDP allows us to bridge the gap between the semantic esoteric world and web api’s that are not semantic. The magic is that turning your api into ldp is very simple. You just have to add the contexts :)

Conclusion

Startin’blox technology aims to provide interoperability between interface in order the make a smarter, opener et more cooperative web to emancipate users.

This page should be improve. Any feedbacks is sooo welcome :)