As said in our what’s next post new API Sifu specification language will be much simpler to learn and use. At the same time, it will enable even give the user, even more, usability and flexibility from the specifications them self.
Here is an example of the user API specification written in new API improvements in the specification language.
UserApi api[secured ADMIN, rest /users]( nonAdmins read[select from User where User.role != ADMIN, response UserResponseDTO, rest /non-admins] adminUsers read[query User.adminUsers, rest /admins, response UserResponseDTO] activeUsers read[select from User where User.active == true, rest /active, response UserResponseDTO, paged] UserResponseDTO dto[model User]( User.id User.email User.facebookId User.googleId User.firstName User.lastName User.birthdate User.active ) UserActivationDTO dto[model User]( userIds list User.id User.active [default false] ) setUserActiveStatus update[select from User where User.id in userIds, request UserActivationDTO, response list UserResponseDTO, rest /active] UserActivationSimpleDTO dto[model User]( User.id User.active ) setUserActiveStatusSimple update[request list UserActivationSimpleDTO, response list UserResponseDTO, rest /active/simple] )
Now the endpoints can be defined with keywords: crud, create, read, update and delete. We’ve stripped down the crud to be as simple as possible and allow the user to expose the whole model in just one line:
specialties crud[model VetSpeciality, rest /vet/specialties]
For more advanced endpoints you can use create, read, update and delete keywords. To define the request and response format you should either predefine a DTO or define it inline.
Here is an example of the specification of create endpoint with predefined DTO’s:
VetResponseDTO dto[model Vet]( Vet.id Vet.user.firstName Vet.user.lastName Vet.user.birthdate Vet.image Vet.specialities ) CreateVetDTO dto[model Vet]( Vet.user.email password text[min 1, max 40] Vet.user.firstName Vet.user.lastName Vet.user.birthdate Vet.user.active Vet.image Vet.specialities dto[model VetSpeciality]( VetSpeciality.id ) ) createVet create[request CreateVetDTO, response VetResponseDTO, rest /vet]
Here is an example of a specification of the read endpoint with inline definition of response DTO:
findOwners read[select from Owner orderable by Owner.lastName, Owner.city, response dto(Owner.id, Owner.firstName, Owner.lastName), rest /owners]
We’ll release a far more detailed tutorial in the coming weeks. Regard this post just as a sneak preview.