Praxis 0.16 examples

45 views
Skip to first unread message

Ashish Gaur

unread,
May 17, 2015, 11:32:17 AM5/17/15
to praxis-de...@googlegroups.com
Hey guys,

We have been using praxis 0.15 since now and would like to upgrade to 0.16.x. I have gone through the changelog which states quite breaking changes around traits. We want to update our code to conform with 0.16 standards but there are no examples to be found. The documentation seems to show the examples for 0.15 version. Is there any other source I can refer to use praxis 0.16 which will help me resolve problem I'll face while upgrading ?

Thanks

Josep Blanquer

unread,
May 17, 2015, 12:44:17 PM5/17/15
to Ashish Gaur, praxis-de...@googlegroups.com
Ashish,

 I believe there aren't many breaking changes around traits (one that I know is that if you used bound variables inside a trait definition, that would need to be changed), but other than that, I'm not sure there aren't many/others. 
 Can you post what error you're getting when upgrading? I can help you out if I see it.

 Cheers,

Josep M.

--
You received this message because you are subscribed to the Google Groups "praxis-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to praxis-developm...@googlegroups.com.
To post to this group, send email to praxis-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/praxis-development/799f61fc-d3cf-4bc7-af2f-3e6b673fab21%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ashish Gaur

unread,
May 18, 2015, 5:23:15 AM5/18/15
to praxis-de...@googlegroups.com, thecuriou...@gmail.com
The problem I am facing is that we had created a common trait to define the version to be used by our resources so something like below:

Praxis::ApiDefinition.define do

  trait :versioned do
    version '1', using: [:path]
  end

  ...

end

and we are using the trait as below:

module V1
  module Resources
    class AuthReset
      include Praxis::ResourceDefinition
      media_type MediaTypes::AuthReset
      use :versioned
      ...

    end
  end
end


When I try to run this with praxis 0.16 it fails giving me the error as below

/home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/trait.rb:108:in `block in apply!': undefined method `version' for #<Praxis::ActionDefinition:0x00000001f33b70> (NoMethodError)
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/trait.rb:104:in `each'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/trait.rb:104:in `apply!'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/action_definition.rb:72:in `trait'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/action_definition.rb:58:in `block in initialize'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/action_definition.rb:57:in `each'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/action_definition.rb:57:in `initialize'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/resource_definition.rb:158:in `new'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/resource_definition.rb:158:in `action'
from /home/ashish/codebase/coef/coef-open-api/design/v1/resources/auth_reset.rb:8:in `<class:AuthReset>'
from /home/ashish/codebase/coef/coef-open-api/design/v1/resources/auth_reset.rb:3:in `<module:Resources>'
from /home/ashish/codebase/coef/coef-open-api/design/v1/resources/auth_reset.rb:2:in `<module:V1>'
from /home/ashish/codebase/coef/coef-open-api/design/v1/resources/auth_reset.rb:1:in `<top (required)>'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/bootloader_stages/file_loader.rb:19:in `require'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/bootloader_stages/file_loader.rb:19:in `block in execute'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/bootloader_stages/file_loader.rb:16:in `each'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/bootloader_stages/file_loader.rb:16:in `execute'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/stage.rb:28:in `run'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/stage.rb:51:in `block in execute'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/stage.rb:50:in `each'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/stage.rb:50:in `execute'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/stage.rb:28:in `run'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/bootloader.rb:118:in `block in run'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/bootloader.rb:116:in `each'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/bootloader.rb:116:in `run'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/bootloader.rb:112:in `setup!'
from /home/ashish/pet_pro/praxis-kit/praxis/lib/praxis/application.rb:62:in `setup'
from /home/ashish/codebase/coef/coef-open-api/config.ru:7:in `block in <main>'
from /home/ashish/pet_pro/praxis-kit/rack/lib/rack/builder.rb:55:in `instance_eval'
from /home/ashish/pet_pro/praxis-kit/rack/lib/rack/builder.rb:55:in `initialize'
from /home/ashish/codebase/coef/coef-open-api/config.ru:in `new'
from /home/ashish/codebase/coef/coef-open-api/config.ru:in `<main>'
from /home/ashish/pet_pro/praxis-kit/rack/lib/rack/builder.rb:49:in `eval'
from /home/ashish/pet_pro/praxis-kit/rack/lib/rack/builder.rb:49:in `new_from_string'
from /home/ashish/pet_pro/praxis-kit/rack/lib/rack/builder.rb:40:in `parse_file'
from /home/ashish/pet_pro/praxis-kit/rack/lib/rack/server.rb:318:in `build_app_and_options_from_config'
from /home/ashish/pet_pro/praxis-kit/rack/lib/rack/server.rb:218:in `app'
from /home/ashish/pet_pro/praxis-kit/rack/lib/rack/server.rb:353:in `wrapped_app'
from /home/ashish/pet_pro/praxis-kit/rack/lib/rack/server.rb:282:in `start'
from /home/ashish/pet_pro/praxis-kit/rack/lib/rack/server.rb:147:in `start'
from /home/ashish/pet_pro/praxis-kit/rack/bin/rackup:4:in `<top (required)>'
from /home/ashish/.rvm/gems/ruby-2.2.1@coef/bin/rackup:23:in `load'
from /home/ashish/.rvm/gems/ruby-2.2.1@coef/bin/rackup:23:in `<main>'
from /home/ashish/.rvm/gems/ruby-2.2.1@coef/bin/ruby_executable_hooks:15:in `eval'
from /home/ashish/.rvm/gems/ruby-2.2.1@coef/bin/ruby_executable_hooks:15:in `<main>'


Is this the use case you're talking about ? If so how should go about it ? The code works fine if I replace the use :versioned with version '1', using: [:path].


On Sunday, May 17, 2015 at 10:14:17 PM UTC+5:30, Josep Blanquer wrote:
Ashish,

 I believe there aren't many breaking changes around traits (one that I know is that if you used bound variables inside a trait definition, that would need to be changed), but other than that, I'm not sure there aren't many/others. 
 Can you post what error you're getting when upgrading? I can help you out if I see it.

 Cheers,

Josep M.
On Sun, May 17, 2015 at 8:32 AM, Ashish Gaur <thecuriou...@gmail.com> wrote:
Hey guys,

We have been using praxis 0.15 since now and would like to upgrade to 0.16.x. I have gone through the changelog which states quite breaking changes around traits. We want to update our code to conform with 0.16 standards but there are no examples to be found. The documentation seems to show the examples for 0.15 version. Is there any other source I can refer to use praxis 0.16 which will help me resolve problem I'll face while upgrading ?

Thanks

--
You received this message because you are subscribed to the Google Groups "praxis-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to praxis-development+unsub...@googlegroups.com.

Josep Blanquer

unread,
May 18, 2015, 11:57:14 AM5/18/15
to Ashish Gaur, praxis-de...@googlegroups.com
oh oh! I see now, you're using a trait to propagate the resource definition version configuration! I actually hadn't thought of using traits to do that :)

So, here's what I think about the situation Ashish:

I believe you shouldn't use traits to do that. I would use a base concern for all the resource definitions of the same version. Traits are more geared towards specific common features like parameters, headers...etc, which show in the docs as commonality. Technically, version could be seen as a common "feature" too but I think that is more of an implementation concern than a "trait". Anyway, this is what I would recommend you do:

Create a common concern for your "v1" resources. Here's an example of how to do it:

module V1
  module Resources
    module Base
      extend ActiveSupport::Concern
      # Common concerns for all resources of this version
      included do
        # Add all the DSL stanzas you want to be executed in the context of the included Resource here
        version '3.0'
      end
    end
  end
end

Then simply include that base concern to all your resource definitions. For example, based on your past above, it would look like:

require_relative 'base' # Assuming you save the base concern in the same dir of your resource definitions
module V1
  module Resources
    class AuthReset
      include Praxis::ResourceDefinition
      include Base
      media_type MediaTypes::AuthReset
      #Delete the trait stanza:  use :versioned      
      ...

    end
  end
end

That is just the typical way to use active support concerns (just in case you're not too familiar with it).

...now, onto another aspect that you should be aware of too:
The latest code in master has greatly improved the versioning code. You will now only define the version string for the resources, and will define the "type" of versioning (i.e. path/headers/params) in the APIDefinition for a given version, which will then apply it to all resources of that version, which is really what makes sense, rather than allowing every resource individually to decide if they are path-versioned or header-versioned (even for the same version).

Anyway, while you upgrade your app, be aware aware of that nicety. You can point your app to the master branch if you want to, or wait a few days or so until we cut a new gem with it. You can find the pertinent information here: http://praxis-framework.io/reference/global-api-information/ (and in the Changelog here: https://github.com/rightscale/praxis/blob/master/CHANGELOG.md )

Let us know if that this solves your issues, or if we can help with anything else.

Cheers!

Josep M.


To unsubscribe from this group and stop receiving emails from it, send an email to praxis-developm...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "praxis-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to praxis-developm...@googlegroups.com.

To post to this group, send email to praxis-de...@googlegroups.com.

Ashish Gaur

unread,
May 19, 2015, 3:21:32 AM5/19/15
to praxis-de...@googlegroups.com, thecuriou...@gmail.com
Thanks a lot Josep :).

I have few more doubts:

# As per CHANGELOG for 0.16 "Deprecated ResourceDefinition.routing. Use ResourceDefinition.prefix to define resource-level route prefixes instead". I assumed that this would imply that if I create a resource named AuthReset then the string 'auth_reset' which was by default appended is no longer being done and I had to explicitly specify it in prefix. But when I upgraded to 0.16.1 my routes still had 'auth_reset' appended to it. How does this deprecation affect anything ?
# I checked the introduction of MediaTypeIdentifier in 0.15 which I thought was an internal change and won't affect anything in using identifier in media type. But then I stumbled upon this line, I am little bit confused(and scared :P) of whether this is really deprecated or not. It seems identifier still returns a string and not an MediaTypeIdentifier. If I upgrade to 0.16.1 do I have to use MediaTypeIdentifier externally in my code instead of using identifier ? Is this a possible use case for future ?

Ashish

Josep Blanquer

unread,
May 19, 2015, 12:19:07 PM5/19/15
to Ashish Gaur, praxis-de...@googlegroups.com
Ashish,

 Responses inline.

On Tue, May 19, 2015 at 12:21 AM, Ashish Gaur <thecuriou...@gmail.com> wrote:
Thanks a lot Josep :).

I have few more doubts:

# As per CHANGELOG for 0.16 "Deprecated ResourceDefinition.routing. Use ResourceDefinition.prefix to define resource-level route prefixes instead". I assumed that this would imply that if I create a resource named AuthReset then the string 'auth_reset' which was by default appended is no longer being done and I had to explicitly specify it in prefix. But when I upgraded to 0.16.1 my routes still had 'auth_reset' appended to it. How does this deprecation affect anything ?

What is deprecated was to use `prefix` inside a `routing` block. So you need to use it outside the block, simply at the ResourceDefinition level. Nothing has changed about that behavior. The normal prefixes continue (and will continue) to match the class name. We just needed to eliminate the routing block piece so we moved the prefix out of it (if used inside, it will still work for now, but it will warn you that it is gonna be deprecated) 
 
# I checked the introduction of MediaTypeIdentifier in 0.15 which I thought was an internal change and won't affect anything in using identifier in media type. But then I stumbled upon this line, I am little bit confused(and scared :P) of whether this is really deprecated or not. It seems identifier still returns a string and not an MediaTypeIdentifier. If I upgrade to 0.16.1 do I have to use MediaTypeIdentifier externally in my code instead of using identifier ? Is this a possible use case for future ?


Here, nothing has changed either (all internal). The comment on that line says that in the future (in Praxis 1.0) we want to change that method to return the actual MedieTypeIdentifier class, instead of the string. But this is a breaking change so we will wait until 1.0 to make it. At that point, any usage of that method if you have any, will have to simply do a .to_s on the result if you want a String. 
For now, again, those are simply warnings, the behavior hasn't changed.

 Cheers,


Josep M.
 
Ashish

--
You received this message because you are subscribed to the Google Groups "praxis-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to praxis-developm...@googlegroups.com.
To post to this group, send email to praxis-de...@googlegroups.com.

Ashish Gaur

unread,
May 20, 2015, 2:06:09 PM5/20/15
to praxis-de...@googlegroups.com, thecuriou...@gmail.com
Thanks Josep :)
Reply all
Reply to author
Forward
0 new messages