Slide 1

Slide 1 text

Building APIs With Rails API 1

Slide 2

Slide 2 text

"Why include a bunch of functionality you're not going to use if you're just building a JSON API? " Leigh Halliday 2

Slide 3

Slide 3 text

Patricia Luz Bastos Software Engineer at @Codeminer42 3

Slide 4

Slide 4 text

4

Slide 5

Slide 5 text

5 Agenda Create application with API mode What is Rails API and AMS? JSON What is API?

Slide 6

Slide 6 text

JSON Is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language. 6

Slide 7

Slide 7 text

JSON JSON is built on two structures: • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array. • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence. These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangeable with programming languages also be based on these structures. 7

Slide 8

Slide 8 text

JSON - EXAMPLE Integer Matrix [ [1,5], [-1,9], [1000,0] ] 8

Slide 9

Slide 9 text

JSON - EXAMPLE Object { “Title”: “Json X Xml”, “Resume”: “O Duelo De Dois Modelos De Representação De Informações”, “Year”: 2012, “Gender”: [“Aventura”, “Ação”, “Ficção”] } 9

Slide 10

Slide 10 text

JSON - EXAMPLE 10 Array of Objects [{ “Title”: “JSON x XML”, “Resume”: “O Duelo De Dois Modelos De Representação De Informações”, “Year”: 2012, “Gender”: [“Aventura”, “Ação”, “Ficção”] }, { “Title”: “Json James”, “Resume”: “A História De Uma Lenda Do Velho Oeste”, “Year”: 2012, “Gender”: [“Western”] }]

Slide 11

Slide 11 text

API Application Programming Interface A set of routines, protocols and tools for building software applications. It is a Interface, a lot tools that permit the Application Programming. 11

Slide 12

Slide 12 text

APIs Since 2006 12

Slide 13

Slide 13 text

API Examples: - Login with Facebook In Mobile Application. - Payment your buy in ecommerce. - Calculate zip code. 13

Slide 14

Slide 14 text

"A decision was made to incorporate Rails API into Rails core . During the last week I’ve been working on this and, today we opened a pull request to discuss the results." Santiago Pastorino - Ruby on Rails Core Team Member 20/Apr/2015 14

Slide 15

Slide 15 text

RAILS API RAILS API was made incorporate in Core Rails in version 5. Its usage is in API applications only, where you usually don't need the entire Rails middleware stack nor template generation. 15

Slide 16

Slide 16 text

RAILS API - Ruby 2.2 or higher - Rails 5 or higher API mode does is remove functionality that you don’t actually need when building an API. This includes things like sessions, cookies, assets, and really anything related to making Rails work with a browser. 16

Slide 17

Slide 17 text

RAILS API 17 It will also change the generators so that it won’t generate views, helpers, and assets when generating a new resource.

Slide 18

Slide 18 text

RAILS API 18

Slide 19

Slide 19 text

AMS Respond with JSON ActiveModel::Serializer allows you to define which attributes and relationships you would like to include in your JSON response 19

Slide 20

Slide 20 text

AMS - EXAMPLE 20

Slide 21

Slide 21 text

AMS - EXAMPLE 21

Slide 22

Slide 22 text

CREATE APPLICATION WITH API MODE 22

Slide 23

Slide 23 text

CREATE APPLICATION WITH API MODE 23

Slide 24

Slide 24 text

24 CREATE APPLICATION WITH API MODE

Slide 25

Slide 25 text

CREATE APPLICATION WITH API MODE 25

Slide 26

Slide 26 text

CREATE APPLICATION WITH API MODE 26

Slide 27

Slide 27 text

CREATE APPLICATION WITH API MODE 27

Slide 28

Slide 28 text

28 CREATE APPLICATION WITH API MODE

Slide 29

Slide 29 text

29 CREATE APPLICATION WITH API MODE

Slide 30

Slide 30 text

CREATE APPLICATION WITH API MODE 30

Slide 31

Slide 31 text

CREATE APPLICATION WITH API MODE 31

Slide 32

Slide 32 text

32 CREATE APPLICATION WITH API MODE

Slide 33

Slide 33 text

33 CREATE APPLICATION WITH API MODE

Slide 34

Slide 34 text

Search and Study Cache our JSON serialization in AMS Throttle abusive clients from overloading our API 34

Slide 35

Slide 35 text

Off Topic 35

Slide 36

Slide 36 text

MeetUps Confs CodeSchool CodeCademy

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Thank You! 43 @patricialuzbast patybastos