Full transcript
0:00so hi um I'm Mato I like decoupled
0:05architectures and um I've been involved
0:08with this kind of architecture for quite
0:11a while now um I think it was kind of
0:15three years ago uh in one of my internal
0:19reviews at lullabot um said my my boss
0:24asked me what would you like to do next
0:27year and I said I would like to get into
0:30a API first project uh that happened and
0:35uh and yeah and now I'm gladly
0:38presenting about this stuff uh lat is a
0:41digital agency uh we do uh not only drup
0:45we love druple but we do other stuff
0:48like content strategy um design we do
0:52react we do a lot of JS stuff uh for uh
0:57clients like uh MBC universities Etc and
1:02they paid for my trip here and I'm very
1:05grateful so if you have the chance come
1:08by the
1:10booth so in this session I will be happy
1:13if you come out of it and you have
1:15learned about uh some of these topics uh
1:18Json API what it is and when to use it
1:21or why to use it in the first place um a
1:25druple module uh we wrote AUP a druple
1:28module um I I hear it's working fine uh
1:32but uh yeah I'm going to give an update
1:34on the status of the of the things that
1:36we have pending of the things that we
1:38implemented and why we did it this way
1:41and the the limitations and how it
1:44Compares with other Solutions like rest
1:46in core or um either uh even the graphql
1:50module um and finally some of the
1:53outstanding problems that we have in the
1:56decoupled world um not just uh for Json
2:00API but also for many other decouple
2:03architectures uh there are tricky
2:05problems uh some of those have Solutions
2:09some others have hacks uh and I we talk
2:13about that hopefully it's not not going
2:15to be rushing through it because it's
2:16towards the end so um Json API their
2:21motto is that they Json API paints your
2:24bike shed and that is because I I don't
2:27know if you ever had to uh design and
2:30API but that is something that everyone
2:32has an opinion on like what's the name
2:36of the property that's going to be there
2:38how are you going to structure the Json
2:40object or how you're going to interact
2:43uh if you're going to use rest or not so
2:45Json API takes that off your way because
2:49it's an opinionated specification and it
2:52tells you what to do and the discussion
2:54ends there so it's pretty nice uh I've
2:58been experiencing success with that with
3:01that bike shedding stopping there so uh
3:05basically what it does it it defines the
3:08transport format of a Json object and
3:12also the interaction on how
3:15you how you communicate with the with
3:18the server so um Json API is uh a
3:22specification a particular specification
3:24that uh tells you how to do things from
3:28the server perspective so then consumers
3:32can make assumptions and work on that
3:35and uh by building a standard what we're
3:37building is a ecosystem of tools that
3:40can be used so uh don't look at this too
3:43much because we're going to go into
3:44detail a little bit but first I want to
3:47um to make a note on the fact that Json
3:51API it's uh it's specification it's a
3:54document and it's a Creative Commons
3:57document which is kind of the closest
3:58that you can get to open source when you
4:01don't have source code and uh it's
4:05completely open uh and uh most
4:08importantly it was developed and run by
4:11ux and front-end experts because I am a
4:14backend developer and I like things that
4:17like kind of cover all the corners that
4:20are very academically correct um but
4:23those things are not the things that uh
4:26are the most easy to use right so this
4:29people um basically what they did is
4:32they have been experiencing some pain
4:34using other specifications and that they
4:38did their wish list H
4:40so what this tells us is that this is
4:44something that is designed to be used
4:47it's designed to be easy to
4:51use so why this one because there are
4:53many right um so one one of the
4:56arguments would be uh one that I just
4:58said that it's easy to use right um
5:01another argument could be um that well
5:06when you see uh and you compare this
5:08with the many specifications that are
5:10out there and I'm not listing all of
5:12them here uh there are there are many
5:15more and this is only talking about rest
5:18specifications you can see that Json API
5:21is not doing too good compared to other
5:23like Uber or Mason or whatever um one of
5:28the good things is the only stable
5:31specification that there is out there
5:33like the only modern uh specification on
5:36top of rest and um and it works really
5:41well especially because as I said before
5:44when you set a standard you can then
5:47build an ecosystem of tools that can
5:51helps you leverage all this all this
5:53information so uh why this one it's
5:57because it's insanely popular there's a
5:59a lot of software built around of Json
6:02API uh it's not just in the Ember
6:05Community although it started from the
6:07Ember Community um but there are like
6:10more than 141 repos and this is just
6:13taking uh their side uh and I know that
6:17there are many many repos that are not
6:19listed there for instance the druple
6:20modu is not there uh probably should be
6:23there um it is not um and also whatever
6:28your language is
6:30uh your preference is there are
6:32Integrations with Json API like there
6:34are more than 18 programming languages
6:37that uh interact in one way or or
6:40another with Json API and uh you have
6:44both client side and service side
6:47implementations like you have uh react
6:51Integrations with Json API and you have
6:53in the front end and you have in the
6:55back end triple Integrations with J API
6:58so that makes it really easy to get that
7:0180% done so you can focus on what is
7:04important which is adding value for your
7:09project one of the things that we
7:11learned uh last drupon is uh how by
7:15reusing and making these assumptions uh
7:19you can build something like the cards
7:21CMS uh which uh I don't know if you saw
7:24that that presentation last year but it
7:27was pretty amazing to see uh how
7:29seamlessly the communication worked uh
7:32from this Ember application and and a
7:35duple side using Json API um so that's
7:39that's what we gain uh another good
7:41thing that I like about the
7:43specification is that is not uh it
7:47doesn't control too much what you need
7:49to do it kind of gives you room and
7:53flexibility like for instance um I like
7:55to highlight the the filters idea uh so
7:59in Json API you can have filters and uh
8:03what all that they say is that when you
8:06do filters you are going to specify the
8:09keyword filter in the uh in the query
8:12string and that's it and that's because
8:15every every server has its uh
8:19ideosyncratic uh implementations of uh
8:22filtering right uh in Drupal we have and
8:26the entity query API and we can query
8:29any any entity and relationship between
8:31entities and it's super powerful but we
8:33need some way to express that as part of
8:37Json API and uh Json API doesn't tell
8:41you how you need to do filters because
8:43otherwise we would be in a corner trying
8:45to do kind of weird mappings right um so
8:49what we did is since we have this room
8:52inside of the filters parameter we
8:54specified in the Drupal module what is
8:58the filter strategy that we're going to
9:00use so now we end up with uh an a
9:04specification that's Json API that
9:06specifies almost everything and then our
9:09specific stuff which is the druple
9:11filtering extension so by providing
9:13those you kind of provide full
9:16documentation on how to on how to use
9:18this um so yeah the the extension system
9:21is pretty
9:22nice um also it it is kind of uh useful
9:28when you follow a particular
9:31specification uh when implementing an
9:34API it is very nice to be able to just
9:37send the front end developer to the
9:40documentation uh not not because you
9:42don't have time for that but because the
9:45documentation and the specification is
9:48kind of more detailed on what you can
9:51and you cannot do with Json API so now
9:54your server uses Json API so you can
9:58just point them by giving them a by
10:01giving them a link and and that's it um
10:04so that's that's pretty interesting that
10:06cleared a lot of support request from my
10:08play at least and so why why am I uh
10:16passionate or I like Json API that's
10:19because uh before I landed there I I
10:23started with um with a decouple project
10:26uh the one what I I was mentioning
10:28before um
10:29so we basically ported the all the
10:33druple ideas and we made a Json out of
10:36it and we send it to the client and we
10:39rendered that in um in a backbone app I
10:42think it was back then um yeah backbone
10:47and and that worked well I mean there
10:49was a lot of success in that project it
10:52was a single website was the coupled and
10:55uh by just making things Json and
10:58sending it over the wire
10:59we got done uh but then the same happy
11:03client wanted a second project and we
11:06wanted to use the same API we realized
11:08that we couldn't use it but there was a
11:10lot
11:11of presentation details and coded in our
11:15API and uh and that was a problem
11:18because uh now we wanted to show things
11:20differently while serving one side we
11:23wanted to to serve a second site but it
11:27had a different design and we had fields
11:29that said uh position title on the left
11:34and a background color red and that
11:37didn't work for the new design so we had
11:39to choose either one or the other so
11:41basically we had to redo the API learn
11:44from our mistakes and we did this second
11:47project uh it also went well until we
11:51got the third
11:54project and uh at that point um I mean I
11:59mean I wanted to see what other people
12:03were doing right cuz this cannot be just
12:05me having these problems right uh I
12:08should have done that before uh but hey
12:11I did it at the end right um so
12:13basically that's when I discovered Json
12:15API I uh debated on using Json API or
12:20how uh By the time graph was not on the
12:24table and uh we went with Json API we
12:27never missed any another feature before
12:30because all the problems that I was
12:32having are known problems and those
12:34known problems have known Solutions and
12:38either you use Json API or uh another
12:42Advanced uh system you're going to have
12:45the same known Solutions applied to it
12:48with some other flavors right inj API
12:51you interact differently uh with the
12:54with the API than with other Solutions
12:57but in the end you you all you sure
13:00solve the same problem so uh implement
13:03the same Solutions
13:05so let's talk a little bit about the
13:08Json API format I'm going to rush a
13:10little bit through this uh because uh I
13:12don't think that this is uh very
13:15interesting uh this is just format right
13:18um so basically there are like four
13:19parts I encoded them with colors the
13:22blue part is the resource information it
13:25this is what identifies a particular
13:27resource like it can be like for
13:29instance a type collection and then the
13:32ID number 23 right um so yeah that's
13:38pretty easy then there is the actual
13:40data uh the attributes and relationships
13:43uh that that you have inside your that
13:46inside of your entity the inside of your
13:48research entity and finally we have the
13:52the Yellow Part which is metadata which
13:54is kind of talking about the data that
13:58you're exposing things look like this
14:00resource was loaded in 75 milliseconds
14:04or that's too fast probably um but but
14:08yeah you also have like links things
14:10that are related to each other and uh
14:14and this kind of metadata and finally
14:16you have some glue code to put
14:18everything together so it looks like
14:20this um the there is the the part with
14:24the uh identifying the resource and this
14:28part to identify a resource is going to
14:30be reused in the relationships because
14:33in a relationship you point to another
14:35resource right uh that's what a
14:37relationship is and uh then you have
14:41attributes and relationships and inside
14:43of that you have just the key values uh
14:46so it's very readable that's uh that's
14:49what I was saying when uh I was saying
14:51that it was designed by ux designers and
14:53frontend developers they want it to be
14:56usable they don't want here an array of
14:59uh name equals whatever and value equals
15:03whatever if it's an array then it's just
15:07plain simple in here I'm just setting uh
15:10a string but this could be whatever this
15:12could be Jon
15:13object and the relationships are kind of
15:17uh fractal in the sense that they
15:19contain the both the sorry all of the
15:22four colors inside them uh but basically
15:25the idea is that you have the key uh the
15:28name of the relationship and then the uh
15:31ID of the thing that they are pointing
15:33to so th this is pretty much it um so
15:38you can see it's easy you may be
15:39confused uh because I went probably too
15:42fast but I guarantee that if you stare
15:45at this uh at this format
15:48for 15 minutes uh you will be the master
15:52of it uh
15:54so resource interaction is even easier
15:59it just uses rest right um the goal of
16:02this talk is not to talk about rest
16:05probably uh you are uh already tired of
16:09uh of hearing about rest but it's
16:11basically using HTTP verbs to do actions
16:15on uh the resources and uh for us like
16:18to get us in the mindset resources are
16:22kind of just entities for for us right
16:24uh we kind of use the same name they uh
16:27in the rest world uh they use the word
16:30entity and we do as well so it's kind of
16:33the same the same thing um so this is
16:37what it looks like you make a guest
16:39request and you get a response um pretty
16:42much that simple the only thing is that
16:46uh you kind of you can pass a list in in
16:50the druple module is kind of optional
16:53you you pass an accept header saying hey
16:57these list of articles I want them in
17:00the format API
17:01Json and that's uh and that's
17:05that uh so we said that we had typical
17:08problems we didn't talk about those
17:10problems um nor the solutions so the big
17:15problems are um related to um to three
17:19big topics one is that uh in rest
17:22typically we have multiple requests to
17:24the back end right and by having
17:26multiple requests to to the back end uh
17:29what we are doing is we are slowing
17:31things down because we have uh multiple
17:34times the HTTP latency from going from
17:38uh my phone in that mountain with low
17:41coverage in 3G to whatever server I'm
17:45hitting right um so if you do that
17:48multiple times it's going to hurt
17:50performance um also when you when you
17:54get an entity in rest you get the whole
17:56thing the whole everything or nothing
17:59it's like when you get the entity drup
18:01goes and gets you everything that's
18:04there
18:05right and finally this content Discovery
18:09um the this is kind of
18:12a an interesting thing because we are so
18:15used of having listings and being able
18:18to find uh every piece of content but uh
18:21that's because druple is pretty awesome
18:23and uh that is not trivial in in other
18:27places things like uh I know how to
18:29access article 12 but I don't know how
18:32to get all of the Articles so um so
18:36those are the the big problems and those
18:38are the the solutions um so let me
18:42highlight those by going through this
18:44extremely uh simple example and believe
18:47me your project is going to be way more
18:50complex than this right um but the the
18:54example is uh that there is a a Blog and
18:57uh my friend Paco wants to do this blog
19:00and the and he likes to talk about
19:02frontend development because he is a
19:04frontend Dev and uh he's also vegan and
19:08wants to talk about that and cats as
19:10well and he wants to write a blog in
19:15kind of this manner this is the this is
19:18the mocks that he has uh there is a
19:20title there is an image for the author
19:23there are comments uh a list of tags
19:26with the name of the tag and then link
19:28to somewhere else are related to that
19:30tag and also the images of the authors
19:33of the comments Etc so uh this is not a
19:38radical design right this seems pretty
19:40simple uh so when he starts doing this
19:43with uh typical rest he says okay I know
19:46that this is article 12 so I'm going to
19:49load that and when I load that I'm going
19:51to load uh the author and when I load
19:55the author uh I will know that the the
19:58author has a a picture and I will
20:00download that so you can see how quickly
20:04that super simple example escalates in
20:07the number of requests but the worst
20:10part of this is not the number of
20:13requests but uh what I have here
20:16represented by the indentation levels
20:18you can see that there are three sorry
20:21four indentation levels here in nine
20:23that means that in order to get the
20:26information that we want about the the
20:29image of the author of the comment on
20:34the article we need to do four
20:37sequential requests that means that we
20:39need to wait for four requests to go to
20:43the server and back and that's what's
20:46bad uh so in Json API we simplify that
20:51by saying to the server uh well that
20:54looks simpler
20:57um when you get the article just
21:01include these relationships follow the
21:03relationships and include the
21:05response all in one go so you make one
21:09single request and you get all the data
21:11that you need so uh that's resource
21:15embedding you are embedding other
21:18resources in your initial request um so
21:22uh that's how you would solve that um
21:25the idea of kind of limiting what you
21:28get back IM imagine that uh he wanted to
21:31get only for uh articles cuz now we know
21:34that when you request an article you can
21:36get also information about authors and
21:38taxs right so you specify the fields for
21:42the articles that you return uh are only
21:46the title and the creation date so it's
21:49basically it's just that this is the
21:51idea you get uh only what you care so
21:55you get all that you want and only what
21:59to want in one single request uh and
22:02that is pretty powerful so the last
22:05thing that um that we said we were talk
22:07talking about was uh collections so
22:11imagine I'm going to switch the example
22:13uh imagine that you're implementing a
22:15record label uh and you want to do
22:17something like this uh give me the cover
22:20image and the publication GE of all of
22:23the albums of all of the Bands having
22:26one of the members and the 35 currently
22:29living in Mia which is a beautiful
22:31region in Spain and uh you can say oh
22:35well you're at it I'll put the name of
22:38the band and the members as well so that
22:41sounds like a lot right but what what
22:44we're saying there is that we want a
22:47list of bands and we want to select not
22:49all of the Bands but only those bands
22:52that one of the members is under 35 and
22:57lives in a particular city right and
23:00then we are also including we know how
23:02to do includes and we are also know how
23:05to select Fields but the important part
23:07here is that we are filtering and this
23:10is a complex filter because we are not
23:13filtering we're filtering bands but
23:16we're not filtering on any property on
23:18the band we're filtering on properties
23:21on the members that belong to that band
23:24right so um the way that you would do
23:28this
23:29is uh you would use the keyword
23:32filter um and you would say the members
23:36the city member is set to
23:40Moria and uh and that's pretty much it
23:43uh you will get all of the bands that
23:46have a member that live there right or
23:48at least that uh you set in Drupal that
23:50lives there and um and you could also
23:53add on top of that another filter that
23:55says the age of of the members has has
23:58to be you set it to 35 and then you set
24:01the operator to less than so uh when
24:05that gets uh interpret it it gets set to
24:08less than 35 uh so that's it then we do
24:11some includes we do some fields and and
24:16again you get a collection with all of
24:18the items that you need that contain all
24:21of the data that you need and only the
24:23data that you need and this is um and
24:27this is what Jason API is all
24:30about so I don't know if you noticed but
24:34that sounded pretty much like a query to
24:36me like uh the fields are kind of the
24:41columns in the SQL statement uh they
24:43includes are joints and
24:47the the filters are the wear so that's
24:51what we're doing we are empowering the
24:53consumers to do Advanced queries on our
24:57system so we can have them build the
25:03data that we need that they need so this
25:07is the This Is The crucial concept if
25:10you walk away with anything out of this
25:14session just remember this the consumers
25:18are the ones that specify their data
25:20needs you as a server or as a backend
25:24engineer you don't have any bus business
25:28saying this is how you will display
25:31data this is uh unfortunately not a
25:35monolithic approach where you can click
25:37a view together and say uh this is how
25:40you're going to get the data no they are
25:43because uh my Xbox application is going
25:46to have a radically different design
25:50than my iPad app and maybe my um Android
25:54app is completely different from my IOS
25:56app and I don't even know if I open up
26:01my API what someone can do with my API
26:05so what what am I doing saying that uh
26:09something needs to be displayed in a
26:11particular way so that kind of reverses
26:15the roles and it's not the server
26:18anymore saying uh I'm going to click
26:20these filters together for a view and
26:23this is what you get but it's the other
26:26way around it's the consumer
26:29that decides what data they need to
26:31implement their
26:33design and they ask for it and uh
26:37basically that kind of as a backend
26:39developer that's kind of cool because
26:41all the work is
26:45there there is a like a a final thing on
26:48Json API I'm not going to go through
26:49this but there are like for every
26:51resource for four different endpoints
26:54uh there's the related data and endpoint
26:58and the relationship data endpoint uh go
27:01and look into into the specification and
27:03and you will you will learn more about
27:06it not sure you notice but I just sent
27:09you to the
27:11manual so I said that there is a
27:13performance gain right um let's let's
27:17talk about that so um I did a very
27:20simple test and please don't chastise me
27:23on how simple this performance test is
27:26uh because I'm aware of it right but I'm
27:28just trying to make a point uh so what
27:31I'm doing here is I'm selecting an
27:33article uh 2100 and I'm including the
27:38author and the image of that article and
27:41also I'm including two tags um just for
27:44fun because we know that the slow path
27:46is going to be uh the three sequential
27:48requests right but I'm going to select
27:50the two tags uh and I'm going to compare
27:53that with um with resting core and uh in
27:57that case we need to make those
27:59sequential requests uh I'm not going to
28:02again I'm not going to bother to do
28:04these two tag requests CU we know they
28:06are not in the critical path So This Is
28:09What It Takes uh with page cache uh in
28:13uh in full motion and uh using my local
28:16to make this test takes 21 milliseconds
28:19which is pretty good right um but you
28:23notice that here if we have more
28:26sequential requests the performance gets
28:28worse right um while if we use uh modern
28:34technique like Json API does with
28:36embedding resources uh we get a flat
28:40around 7 milliseconds and that's three
28:43times the performance but it's not only
28:46three times the performance because if
28:47we had
28:48like nine levels of indentation it would
28:51be nine times better um so this kind of
28:55uh is uh stable performance game is
28:59stable if you uh get uh Anonymous
29:02traffic cached by PES cach or
29:04authenticated traffic uh cashed by
29:07Dynamic cash or even uncashed traffic so
29:10it's kind of um a
29:12very uh I would say that uh it's
29:16fairly safe to say that the performance
29:19is is better and it's a linear gain uh
29:22so there are more details on how I did
29:25this in the gist there if you're curious
29:27um um but yeah basically what we are
29:30doing here is we avoiding druple to
29:33bootstrap multiple times to get the data
29:37right uh but it's not only that right
29:39because uh again if I'm with my uh very
29:43bad signal on my phone and I need to do
29:48the round trip to the server uh maybe it
29:50takes 300 milliseconds and if you have
29:53to go nine times and do 300 milliseconds
29:56that's 3 seconds to load instead of 300
29:59milliseconds plus 7 milliseconds right
30:03so uh it is really important and uh I
30:07would say that without something like
30:10this without resource embedding uh with
30:13Json API or with something else uh the
30:16performance in a decoupled app is you
30:19know is just not acceptable so you need
30:22to do some of
30:24this uh so let's talk about the the the
30:28Drupal module um so basically the Drupal
30:32module has been uh oh yeah that's where
30:35you download the the druple module uh
30:39basically the idea of the druple module
30:41is that it's zero configuration so you
30:46download the druple module you enable
30:49the Drupal module and you're done you
30:52have a fully functional full featured
30:55Json API server
30:58[Applause]
31:12so um that means that uh not only you're
31:16able to interact with the entities not
31:18just reading right we're not talking
31:20here only about reading data my examples
31:23were about reading data but uh we are
31:26also going to have to need to write data
31:29to delete entities to update them Etc um
31:33so uh you can do uh you can do all of
31:37that uh by by default it also integrates
31:40with whichever authentication provider
31:44uh you have enabled in your system and
31:46you if you add a new one it gets added
31:49to to the list so if your request is
31:52legible to authenticate uh then it gets
31:55authenticated uh it's it's that simple
31:58um it's tied to the entity system and uh
32:03this kind of was a not a heated
32:05discussion because it's uh it's hard to
32:08have a heated discussion with whim leers
32:10but uh it it was an interesting
32:13discussion on if we wanted to limit
32:15ourselves into the entity system and uh
32:19we said yes and uh I'm very happy that
32:23that we did uh cuz um cuz that kind of
32:26reduces complexity and makes the mod
32:28more stable um so yeah it integrates
32:32with the uh there is full cability
32:34metadata support uh you saw before that
32:37we uh did uh a performance test with uh
32:41Dynamic page cache uh which indicates
32:43that we have that support and uh it
32:46works really well with computer Fields
32:49so things that you want to add extra to
32:52your API just create a Computing field
32:55and it
32:56works um and and we took the stance to
32:59also make a onetoone mapping to
33:02resources to bundles right uh that means
33:07that the there is a different resource
33:10to get articles and there is a different
33:13resource to get Pages they there is no
33:17such con concept of getting a note and
33:20that's because if I ask you what is the
33:23list of fields in node
33:2645 you don't know and that's because you
33:30you don't know if it's an article a page
33:33or whatever uh you can only derive a
33:37full schema from a bundle right um and
33:41that's why we decided to go with the
33:43idea of tying the resources to to
33:46bundles that has the unfortunate
33:49limitation that you cannot make a
33:50listing that kind of
33:53intermixes Articles and Pages uh I don't
33:58think that that's very useful the I mean
34:00there is that use case um but you can
34:04make the two requests maybe uh with that
34:07um I haven't found uh a use case for
34:11selecting all of the bundles on an
34:14entity type that was kind of um that
34:18would justify going that direction uh so
34:21what can we what do we gain uh as part
34:25of that um what we gain is that we can
34:28create a schema and there is a and there
34:31is a module called schemata and uh that
34:35module has now full support for Json API
34:38and the full support for Json API uh
34:42what will give you is a document uh it
34:47is also Json but it's just a document
34:50that explains the shape of the Json API
34:56output so it kind of tells you uh that
35:00there is um
35:02data property that contains a list of
35:05for for an article for instance that
35:08contains a list of properties that let's
35:10say an nid that nid is an integer that
35:14contains a body the that body is an
35:16object that contains value which is a
35:19string format which is another string so
35:23the use of that is that you can generate
35:26automatic documentation
35:28and uh by generating automatic
35:30documentation uh you get the ability to
35:34uh just make sure that you have your
35:37documentation up to date so when you
35:39create a field in trupo the
35:41documentation is for your API is
35:44automatically updated uh so the
35:48consumers the frontend developers can
35:51just go and look at the documentation
35:54and trust it and know that in they know
35:58that it's up to date and they don't have
36:00to go and make random calls to your API
36:03to inspect the data that they got they
36:06they get back to see oh I see that the
36:09body is not uh a string it's an object
36:12that contains uh the key value right CU
36:16they have here uh what they need and uh
36:19this human
36:21readable uh output here that you see is
36:25uh created by uh a small project called
36:28Doxon that it just slaps some JavaScript
36:30on top of the on the esemar output um so
36:35that's what what you can do with um with
36:37the schema oh you can also generate
36:40automatic forms Cu uh now you know that
36:44the title is a string that the article
36:48has a title that it's a string so you
36:50can pass that to a software that writes
36:54automatic forms for you the cool thing
36:56is that you add if you add a Boolean in
37:00your back end your front end can
37:03automatically create a checkbox for
37:08that so
37:11um you can also validate your input so
37:15if you're going to send a Json blob to
37:17create a comment for instance if you
37:20have downloaded previously the schema
37:23for comments you can just validate that
37:25the thing that you're sending is
37:28useful is valid and that you didn't miss
37:31one of the required Fields
37:33Etc you can do more things you can
37:36generate uh you can even generate
37:39boilerplate code uh so uh this software
37:43here what it does is it generates go
37:46models based on Json API sorry on Json
37:49schema data so um you can kind of get
37:54your start uh you can get a jump start
37:58on your on your project by generating
38:01code automatically so you can see that
38:03you can do a lot of stuff by generating
38:06a schema and we can only do that because
38:09we know that we are going back to a
38:12druple bundle uh and that's when we can
38:14generate the
38:16schema some of the limitations are um
38:20the file Integrations they need work uh
38:24they also need work in druple core uh
38:27but uh but yeah I mean uh it's something
38:30that we we need to to get there like
38:32uploading a binary file is uh still kind
38:36of in a in a rough place um getting
38:41also uh image derivatives uh working uh
38:46so the consumer can select which image
38:49they want uh is also kind of a difficult
38:53uh it's limited to The Entity system so
38:55you cannot for instance expose uh DB log
39:00entries which is something that you may
39:02want to do uh but you can't uh we gain
39:06too much from limiting ourselves to The
39:08Entity system that this is kind of a you
39:10know pros and cons right um it's a good
39:14limitation but still limitation um and
39:18extensible through code only is no
39:21that's no longer true uh cuz uh thanks
39:25to American Airlines actually cuz they
39:27canceled my flight and I got some extra
39:29time
39:33and and got this this worked um a little
39:36bit so it's that module is still not
39:39there yet um but but I'm really excited
39:43because uh it kind of ties back to this
39:45druple philosophy of empowering Site
39:48Builders and this will allow you to kind
39:51of modify some of the things edit the
39:55default routes uh read name some
39:58properties disable some Fields cuz
40:00sometimes you don't care about the
40:01content translation status field right
40:04especially uh in in the US you do it all
40:09all in English uh so um well that's not
40:12fair um but anyways uh you get the idea
40:16uh sometimes you don't care about the
40:18version ID field um so yeah there are
40:21some open challenges
40:24um things that are very complicated did
40:27like uh should we take a stance and do
40:32some image derivatives in the server on
40:36how we think that an image should be uh
40:38cropped and displayed in the in the
40:42consumer I think we shouldn't but uh
40:45again we don't want the consumers to
40:47download your uh 8 megabyte picture
40:51right so we need to do something there
40:54uh so that is an one of the open
40:55challenges um there there are uh other
40:58challenges like uh what happens when you
41:00want to do this trick of doing multiple
41:03requests to the server but for right
41:06operations um uh there is no good answer
41:10in in the Json API module uh I wrote a a
41:15module that kind of will take a
41:17blueprint of
41:19requests uh it's it's usable but still
41:24uh it has its own limitations as well so
41:27so uh well there are there are a bunch
41:30of things that uh are tricky like we get
41:34uh we can get a date in a format that we
41:38don't want maybe we want in
41:40ISO uh in the iso format uh
41:44in on the client's basis like I want to
41:48be able to specify the format of my
41:51dates uh and that is something that uh
41:54we are not there yet so if you want to
41:57contribute to any of this stuff uh
41:59please come to the Sprints if you don't
42:01want to contribute to any of this stuff
42:03come to the Sprints and work in
42:04something else um but especially if you
42:08are a first time contributor uh I think
42:10it's amazing like the mentor Sprints are
42:13uh like one of the best parts of the of
42:16the
42:17drupon before I go I want to say thanks
42:20to uh to these people I don't know any
42:23of them but they
42:25made this presentation to be to be kind
42:29of beautiful I like it uh and so this is
42:32all creative comments stuff so uh thanks
42:35to them and uh if you like the session
42:39please go and kind of evaluate it um
42:44because this will help presenters and
42:47this this doesn't go only for for this
42:49session uh this will help presenters to
42:52get a better chance to present in the
42:53future and um and yeah if you you didn't
42:57like it you can forget about
43:00it that's it
43:02[Applause]
43:12tada do you have time for questions uh
43:15yeah yeah go ahead uh is this
43:20working is this working no is working it
43:24seems it is working okay uh so to CLK
43:27clarify your question on or clarify your
43:30sub request subm module is that to work
43:33with q and batch API
43:39requests so since I'm not sure that that
43:42could capture uh I'm going to try to
43:45repeat the question um is the sub
43:48request module uh intended to work with
43:52Q uh batch API Etc and the answer is no
43:57uh it's it's not that fancy I mean all
44:00all that it does it allows you to
44:04serialized or to send serialized HTTP
44:08requests and send a collection of them
44:11so druple can execute them all and
44:15return in one go the only fancy thing
44:17that it does is that it will allow you
44:20to say request number three expects
44:23request number one's output so go to
44:26this property in request number one
44:29output and put it here in request number
44:31three is there a way of doing uh Q or
44:35batch operations with Json API either
44:37the module or in the
44:42specification is there a way of doing a
44:45batch or Q API operations either in the
44:48Drupal module or in the
44:52specification not yet and to be honest I
44:55didn't think of that and I think it's uh
44:57it's a very interesting
45:00feature just is this working okay uh
45:04just real briefly I really appreciate
45:06locking it down to the entities uh
45:08because I understand the convenience but
45:11uh the problem for me is that if 99% of
45:15my API is covered by that uh and then
45:18all of a sudden I need an API endpoint
45:20that doesn't that isn't entity related
45:23and I have to give out to the client to
45:25the consumers a separate API end point
45:28uh that seems unusual is there like a
45:31wrapper or some solution you have for
45:34dealing with mixing the Json API with
45:39something else uh when when I need to go
45:42beyond
45:45entities yes and
45:48no so so the idea is that you still have
45:53resting core to do all that and it will
45:56allow you to create the Json API output
45:59like uh the example that I gave is about
46:02logging but that is not very interesting
46:04because logs do not relate to anything
46:07and nothing relates to logs right um so
46:11that is the big disconnect there in
46:14order to Traverse the the data model
46:18three and follow relationships and do
46:21queries of things that relate to things
46:24like the example that I gave uh on
46:26filtering on the members data that
46:29belong to a
46:31band you if they are not entities we
46:34don't we cannot use entity query to to
46:38do that query
46:40so you can fake that it's Jon API you
46:45can put it in a route that uh is
46:47compatible with the rest but you know it
46:50will always be a little bit foreign to
46:53the rest of the data model because it is
46:55it's not an entity
46:58thank
46:59you hi you said that the API has right
47:03capability as well inside of Drupal does
47:05that mean that I could use it for
47:07something like a syndication model where
47:09I have let's say 200 Drupal sites that I
47:13want to have them push to a central
47:15syndication server uh to push out to
47:19either other services or for
47:21application uh access or something like
47:25that item see why you couldn't yeah I
47:28think that you can so I could I could
47:30set up something like a a an on update
47:34push a Jason a get um request over to
47:39the syndication server or something like
47:41that yeah you would need to do some
47:45custom code minimal custom code for that
47:48but yeah I think so okay thank you very
47:50much you're
47:52welcome do the uh the entities that it
47:55supports is that uh content content
47:57entities as well as config entities or
47:58are you limited to content I should have
48:00said that yes it's both okay it's both
48:03good so you can uh if you're into that
48:07you can update uh the placement of your
48:10blocks from a remote place cool thank
48:14you for instance or do something
48:17useful uh yeah uh my question is about
48:19permissioning on certain Fields uh say
48:22you have your band uh explanation there
48:25um if you had like the middle name of a
48:28member but you didn't have access to
48:30that how would your API say you
48:32requested it would you just get a 404 or
48:35401 or would you get all the data that
48:37you had requested that you had access
48:40to access control is trickier that you
48:46would expect or at least would I expect
48:48it um so the thing is that um when
48:52you're selecting Collections and one of
48:55the items that would be inside of that
48:59is 403 cuz it's not yet published right
49:02you don't want to fail the whole request
49:05because there are legit items in there
49:07right so um I wrote an extension that is
49:12called partial success that will allow
49:15you to overall get the 200 but for those
49:21things that failed you get uh meta uh
49:26you remember that we talked about the
49:28meta section there is in the meta
49:30section it says uh by the way there was
49:33a bunch of things that gave me a 403 or
49:36401 and in there you kind of get that
49:39output and if you are authenticated it
49:43will even give you stack trays in the
49:45Json excellent thank
49:49you uh another qu another question I had
49:52was about removing Drupal isms from from
49:55the API uh front-end developers that I
49:58work with uh don't like so like when
50:00they see field underscore and so in say
50:03Drupal 7 I have to to write complex
50:06mapping and to flatten apis down uh and
50:11and complex uh definition so is there a
50:13way to hook into uh or alter the the uh
50:18uh the input and you know the request
50:20and
50:22response there are three ways to do that
50:25uh in level of inconvenience would be uh
50:29hooking to the normalization system uh
50:32which which is I don't want to
50:35right the the other way would be um
50:38field API lets you configure the prefix
50:42so you could set the prefix to an empty
50:45string and have your Fields named uh
50:48correctly from from the start which can
50:51have Collision uh Collision problems uh
50:55and the last and of probably the option
50:57that you were uh expecting is that that
51:00module that I said that I wrote recently
51:03and I'm going to publish will give you a
51:06configuration entity that kind of uh is
51:09a companion of the resource and lets you
51:12do exactly that it lets you rename every
51:14field from the UI and you know disable a
51:18resource or rename the route
51:22whatever thank you and I have a last
51:24question is um if if probably would be
51:28possible to to allow type data data
51:32types to be exposed through Json API as
51:34well although you know through some
51:36custom code so is is that possible to to
51:39then Expose and and use type
51:42data type data we are using type data
51:47and exposing that when generating the
51:49schemas so uh what we are doing for to
51:53generate the schemas is we are using
51:55normalizer
51:57on the type data not on the entity but
52:00on the type data behind the entity right
52:02the data definition right exactly the
52:04data the data definitions uh so it's not
52:07directly in Json API uh but is
52:11accessible through SCH so if it would be
52:15possible to um instead of using entity
52:19queries um uh have an endpoint to a
52:23lower level type data or um a complex
52:26data that's not an
52:28entity uh which there are very few of
52:30but is it is a possibility um and then
52:33and and maybe you know instead of going
52:36you know write custom Cod instead of
52:37going through entity field query go
52:40through um your own custom uh data
52:45collection it's not possible and
52:49probably it's not going to be possible
52:52cuz I went that route in Triple 7 and
52:55there is a lot of complexity that goes
52:57with that
52:59flexibility
53:03okay but it should be extensible enough
53:06for uh a separate cont trip to allow
53:20that thank