Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building APIs With Rails API

Patricia
November 11, 2017

Building APIs With Rails API

Escrever APIs usando ActiveModelSerializer é uma forma de utilizar algo que atualmente já foi integrado ao core do Rails a partir da versão 5 e permite escrever APIs padronizadas de uma forma descomplicada, o que te dará agilidade no desenvolvimento. O ActiveModelSerializer basicamente permite usar um serializer para formatar a resposta JSON. Ao criar um projeto usando o Rails API, significa que sua aplicação será mais leve, pois terá apenas os elementos que ela precisa para funcionar.

Patricia

November 11, 2017
Tweet

More Decks by Patricia

Other Decks in Programming

Transcript

  1. "Why include a bunch of functionality you're not going to

    use if you're just building a JSON API? " Leigh Halliday 2
  2. 4

  3. 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
  4. 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
  5. 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
  6. 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”] }]
  7. 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
  8. API Examples: - Login with Facebook In Mobile Application. -

    Payment your buy in ecommerce. - Calculate zip code. 13
  9. "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
  10. 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
  11. 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
  12. RAILS API 17 It will also change the generators so

    that it won’t generate views, helpers, and assets when generating a new resource.
  13. AMS Respond with JSON ActiveModel::Serializer allows you to define which

    attributes and relationships you would like to include in your JSON response 19
  14. Search and Study Cache our JSON serialization in AMS Throttle

    abusive clients from overloading our API 34