CakePHP in 2010. API experience - Personal/startup projects - Open Source - Private/commercial - Public/government Chris Nizzardini | @cnizzardini API Documentation and Tooling with OpenAPI
respondents have 3 years or less API development experience. • Over 60% spends 10 hours or more per week on API development. • API usage is split almost evenly between internal (52%) and external. • More than half said API documentation is either below average or not documented well at all. • The most helpful enhancement API producers can make is to provide better examples in the documentation (63.5%), followed by standardization (59.4%), and sample code (57.8%). Source: https://www.postman.com/resources/infographics/api-survey-2019/
◦ Time consuming ◦ Can become dated quickly depending on release cycles ◦ We never built any and it’s too much work now. • Not a priority ◦ Doesn’t add revenue ◦ We don’t have the time • We simply don’t know how • We don’t care enough for all the reasons above
internal engineers ◦ Streamline implementation of your commercial API for external developers • Support inquiries cost money ◦ Reduce support inquiries with a well documented API • Your documentation is the user interface for your API ◦ A website with an ugly UI is a red flag and so is an API without good documentation • Marketing matters and documentation is marketing • We can “automate” portions of our documentation with OpenAPI tooling
schema etc. • Formally known as Swagger (1.0 - 2.0) • YAML / JSON • Has a robust tooling ecosystem: ◦ SwaggerUI ◦ Redoc ◦ Client Generators ◦ OpenAPI schema can be imported directly into Postman
properties: name: type: string City-Add: type: object required: — name allOf: — $ref: ‘#/x-custom/components/schemas/City-Write’ Custom vendor extensions do not appear in Swagger or Redoc (though each have their own extensions). We can use these to provide custom schema and parameters and avoid cluttering documentation views.
my existing CakePHP be converted into OpenAPI? ◦ We already have: ▪ RESTful routes ▪ Controllers ▪ Models ▪ Validations ▪ Doc Blocks ▪ Data Transfer Objects ▪ Authorization ▪ Pagination • So just bake it for me. Okay...
* Returns a list of Cities * * @Swag\SwagPaginator() */ public function index() { // ...code } get: summary: ‘List Cities’ description: ‘Returns a list of Cities’ parameters: — name: ‘sort’ in: query schema: type: string enum: — id — name — created — $ref: ‘#/x-swag/components/parameters/PaginatorPage’ — $ref: ‘#/x-swag/components/parameters/PaginatorLimit’ — $ref: ‘#/x-swag/components/parameters/PaginatorDirection’
community use for API development? • CRUD Exceptions • Response Formats: HAL+JSON and JSON-LD • RESTful baking themes • Auto routing • Could we use a plugin specifically designed for API development?