pREST A RESTful API from any PostgreSQL database

pREST A RESTful API from any PostgreSQL database

How to use pREST

308dfe1398173b9576bc23829fb9b92e?s=128

Felipe Oliveira

April 18, 2017
Tweet

Transcript

  1. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 1/26 pREST A RESTful API from any

    PostgreSQL database 18 April 2017 Felipe Paes de Oliveira Go Developer at Nuveo
  2. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 2/26 Como surgiu o pREST? Nuveo v2

    Remodelando para uma estrutura menos rigida Nuveo v1 em Go e MongoDB Nuveo v2 Go e PostgreSQL com suporte a JSONB Reescrever todas as queries de todos os sistemas postgREST (https://github.com/begri s/postgrest, Haskell), di cil de manter em produção
  3. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 3/26 Sobre o pREST Primeiro commit 22

    de Novembro de 2016 (by @avelino) 7 releases (versão atual v0.1.6) Suporte as operações de CRUD Suporte a JOIN Suporte a execução de scripts SQL Autenticação via JWT Sistema autorização CORS Con guração: Flag > Env > TOML le Sistema de migrations Pode ser usado como aplicação ou package
  4. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 4/26 Padrão pREST URLs: /DATABASE/SCHEMA/TABLE HTTP GET

    = select HTTP POST = insert HTTP DELETE = delete HTTP PUT = update HTTP PATCH = update Query string não começa com _ = clausula where Query string começa com _ = query operations eg: JOIN ou paginação { "data": { "FIELD1": "string value", "FIELD2": 1234567890 } }
  5. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 5/26 Filtros Sem campos JSONB /DATABASE/SCHEMA/TABLE?FIELD=$eq.VALUE Com

    campo JSONB /DATABASE/SCHEMA/TABLE?FIELD->>JSONFIELD:jsonb=$eq.VALUE
  6. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 6/26 Outros operadores

  7. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 7/26 Operadores Na clausula where podemos omitir

    o operador $eq /DATABASE/SCHEMA/TABLE?FIELD=VALUE = /DATABASE/SCHEMA/TABLE?FIELD=$eq.VALUE
  8. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 8/26 JOIN /DATABASE/SCHEMA/TABLE?_join=inner:users:friends.userid:$eq:users.id

  9. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 9/26 Operadores

  10. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 10/26 Usando o pREST como package func

    main() { // Reorder middlewares middlewares.MiddlewareStack = []negroni.Handler{ negroni.Handler(negroni.NewLogger()), negroni.Handler(negroni.NewRecovery()), negroni.Handler(negroni.HandlerFunc(CustomMiddleware)), } // Get pREST app n := middlewares.GetApp() // Get pPREST router r := router.Get() // Register custom routes r.HandleFunc("/ping", Pong).Methods("GET") // Call pREST cmd cmd.Execute() }
  11. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 11/26 Case Filmow

  12. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 12/26 Case Filmow Usa o pREST como

    package Uma parte de Django pra Go
  13. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 13/26 Vantagens

  14. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 14/26 Performace: Django

  15. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 15/26 Performace: pREST

  16. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 16/26 Desvantagens

  17. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 17/26 pREST dentro da Nuveo

  18. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 18/26 pREST dentro da Nuveo Usando como

    app
  19. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 19/26 Vantagens

  20. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 20/26 Vantagens Expõe uma app com o

    banco de dados Agiliza o desenvovimento de operações de CRUD
  21. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 21/26 Desvantagens

  22. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 22/26 Desvantagens O código não deixa claro

    que está acessando o banco de dados Esconde muito a complexidade do código
  23. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 23/26 Proximos passos Melhorar buscas com JSONB

    Melhorar mensagens de erro
  24. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 24/26 Para saber mais Site do pREST

    (http://postgres.rest)
  25. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 25/26 Thank you Felipe Paes de Oliveira

    Go Developer at Nuveo felipeweb.programador@gmail.com (mailto:felipeweb.programador@gmail.com) https://www.felipeweb.net.br (https://www.felipeweb.net.br) @_felipeweb (http://twitter.com/_felipeweb)
  26. 5/4/2017 pREST http://localhost:3999/pREST_Usage/prest.slide#1 26/26