Creating a JSON API with Athena & Granite

#1
#2

That’s pretty neat. Thanks for sharing!

Btw, it’s very well-written. Great job!

1 Like
#3

This has since been updated to work with the newest Athena version.

#4
field updated_at : Time, annotations: [
      "@[CrSerializer::Options(expose: true, readonly: true)]",
    ]

annotations can not be on macro?

@[CrSerializer::Options(expose: true, readonly: true)]
field updated_at : Time

in a string is not good.

#5

but property also is a macro.

JSON::Field also on it.

#6

Athena is more like spring mvc.

#7

Unfortunately it’s a limitation with how Granite builds out its properties. Since the field macro does not create the property itself, having it just above it does not work. However i’m getting closer to having my annotation ORM prototype done, then it would look more like

@[TBD::Column]
property updated_at : Time?

Which is just another ivar property with an annotation, much cleaner looking, also the type/name is infered from the ivar itself. the annotation could also be used to have alternate DB column names, like @[TBD::Column(name: "updatedAt")]

Similar in the way they use annotations, although it was originally based on Symfony.

#8

code first like .net EF?

#9

Possibly. It’s still in the early stages. I did put in some time into making a pretty decent migrator, so it should be possible to generate the tables based on the model definitions. We’ll see how it goes :stuck_out_tongue: