Giter VIP home page Giter VIP logo

jsonapi-rb.github.io's Introduction

jsonapi-rb

Ruby gem for building and consuming JSON API documents.

Status

Gem Version Gitter chat

Resources

Code

jsonapi-rb is simply a bundle of:

For framework integrations, see:

Installation

# In Gemfile
gem 'jsonapi-rb'

then

$ bundle

or manually via

$ gem install jsonapi-rb

Usage and documentation

See jsonapi-rb.org/guides.

License

jsonapi-rb is released under the MIT License.

jsonapi-rb.github.io's People

Contributors

alsemyonov avatar aniketschneider avatar aprescott avatar beauby avatar dawidof avatar luciusgone avatar musaffa avatar packetmonkey avatar patch-malone avatar smaximov avatar vdmgolub avatar zemptime avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

jsonapi-rb.github.io's Issues

Recommended setup for jwt tokens

Hey. I'm converting a smallish API over from AMS onto jsonapi-rb. Loving the experience thus far. I have a question on how to do a thing.

I've got a registration endpoint for when users sign up.

  def create
    @user = User::SignUp.new(registration_params)

    if @user.save
      jwt = Auth.issue({user: @user.id, name: @user.name})
      render jsonapi: {jwt: jwt}, status: 201
    else
      render jsonapi: @user, status: 200, serializer: ActiveModel::Serializer::ErrorSerializer
    end
  end

For sad path, swapped out

# this:
      render jsonapi: @user, status: 200, serializer: ActiveModel::Serializer::ErrorSerializer
# for this: 
      render jsonapi_errors: @user.errors

And it just worked, all tests passing. Woo!

For the other part, where I'm serializing up a JWT, I basically got stopped and confused in the documentation on this page right here:

This behavior is customizable by overriding the jsonapi_class setting (or by supplying a class renderer option). Either set it to an explicit hash, or a hash with a dynamic default value for inferrence.

I got the impression I need to write some code somewhere, specifically tie a class to a hash or something somehow so I could use jsonapi-rb to serialize up my JWT.

shortly after, while listlessly scrolling upwards on the page unsure where to go, I then realized it was right there on the page, this link.

Anyway, I'm still not sure exactly what the right thing to do is. So I wanted to articulate in this issue, here's what I was trying to do, here's where I got confused, and ask for help.

What's the right way to serialize up my jwt? If I have a "virtual" resource that doesn't correspond with a db table, how can I get my endpoint working right away without needing to build out an entire mental model of how the rest of this works? that would be a great dip my toe in the pool moment, where I could dig into the rest of the docs at the point in time I need them.

But then I'd also like to offer to bulk up the documentation from the POV of someone using this library for the first time. Would you be open to me PR'ing in some "if you want this outcome, do this" quick and dirty examples for that getting started on rails page? And if it ends up being good, I'd be happy to PR in doc enhancements in other areas as I progress in my usage. :)

Anyway, hope this issue is in the right place, and thank you so much for your work on this. I'm planning on building cool things with it!

Add docs for migrating from AMS.

Identified gotchas:

  • attribute :foo, key: :bar: in AMS, this creates a bar attribute in the JSON output. In jsonapi-rb, this becomes attribute(:bar) { @object.foo }.
  • some other stuff I haven't identified yet.

Consider a different font or increasing char spacing?

The rendered site is really painful on the eyes. The character spacing is nearly nil and the font color isn't quite black so blends in even more. I'm getting old so I asked around to the younger crowd and my informal poll resulted in strong dislike from a 20yo, 30yo, and 40yo so it's not just me. One guy actually had to inspect the page and change the body font before he could continue. I'm not trying to be malicious, I just wanted to ask around before I opted to bother you with such a request.

screen shot 2018-10-29 at 6 24 27 pm

Hanami serialization example is wrong

I suppose there is an example that is wrong about hanami framework.
the file is located at source/guides/serialization/rendering.html.md.

The example says:

module API::Controllers::Posts
  include API::Action
  include JSONAPI::Hanami::Action

  expose :url_helpers

  class Create
    # ...
    @url_helpers = routes  # Will be available inside serializable resources.

    self.data = posts
    self.include = [:author, comments: [:author]]
    self.fields  = { users: [:name, :email],
                     posts: [:title, :content] }
  end
end

It should be like this:

module API::Controllers::Posts
  class Create
    include API::Action
    include JSONAPI::Hanami::Action

    expose :url_helpers

    def call(params)
      #...
      @url_helpers = routes  # Will be available inside serializable resources.

      self.data = posts
      self.include = [:author, comments: [:author]]
      self.fields  = { users: [:name, :email],
                       posts: [:title, :content] }
    end
  end
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.