rest api code completion for javascript - dotjs 2015

Post on 16-Apr-2017

1.408 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

QUICK RECIPE:HOW TO END MANUAL REST-API CLIENT CODING

@johannes_fiala

Calling APIs manually

$.getJSON(backend_url ???, data ???, function(response) {

response.???

}

Calling APIs using a generated SDK

Ingredients

Swagger API docs need to be supplied by the API provider can be provided automatically using e.g.

Spring Boot + Swagger-Springfox see Swagger.io – Tools & Integrations You can also do “API first“ using Swagger-Editor

Swagger-Codegen generate client code in 20+ languages Static Javascript support requested in 2013 … added during dotjs 2015 … available since 2015-12-07 05:00

Sample REST model using Spring Boot + Springfox

Swagger API exampleModel definition

Steps to generateJavascript client code Prepare

Checkout Swagger-Codegen

Generate Generate JS client stubs

Code Enjoy code completion for the REST

API in Javascript & HTML

JS Mustache templates for Swagger-Codegen

Generate client code using Swagger-Codegen

java -i http://localhost:8080/v2/api-docs -l javascript -o c:/myproject

Generated Javascript Model:

Code completion for User

Code completion in HTML

Code completion for all API operations

Current state of Javascript support API support

Jsdoc comments + type hints Model support

Jsdoc comments + type hints Enumeration support Getter/Setter support Constructor for required properties Print using toJson()

Plain JS + AMD usage supported

It‘s not yet perfect …

Support for Typescript data types, inheritance, interfaces,

enumerations More annotations / decorator support

See Java Bean Validation API: @NotNull, @Size, @Min, @Max, …

???

It‘s up to you …

Thank you for your attention! Swagger-Codegen:

https://github.com/swagger-api/swagger-codegen (master / scheduled for release 2.1.5)

Full demo for Spring Boot: Devoxx 2015 @Youtube

Questions?Contact: @johannes_fiala

Resources

Swaggerhttp://swagger.io/

Swagger-Codegenhttps://github.com/swagger-api/swagger-codegen

Spring Boothttp://projects.spring.io/spring-boot/

Swagger-Springfoxhttps://github.com/springfox/springfox

Swagger-UI https://github.com/swagger-api/swagger-ui

top related