Comments (4)
This may be the solution to my problem, but is there no way to stop sinja from deciding where to put dashes in controller names (routes)? I have updated my test repo @ https://github.com/jgnagy/test-api (which happily works now thanks to #12 being resolved), but it takes the TestKey
and forces the route to be /test-key
. What if I didn't want a dash, and instead simply wanted /testkey
? Is this configurable? If not, maybe this is something I could help with / submit a PR for.
from sinja.
Sinja draws the routes based on the symbol passed to the resource
keyword. The symbol is dasherized and pluralized. Currently, there's no way to override this behavior, which is what this issue is intended to track. It's something I'm willing to prioritize if it helps an early adopter!
All that being said, your resource is named :keys
, so the resource route should be /keys
, not /test-keys
. I think you may be looking at the links in the response payload. These are actually generated by JSONAPI::Serializers, and it is customizable! Just override the type
method in your serializer class:
class TestKeySerializer
include JSONAPI::Serializer
attribute :name
attribute :created_at
def type
'testkey'
end
end
More information is available here.
This does create a bit of a problem because the links in the payload must line up with the routes drawn in the Sinja application (or else the consuming application may try to access a URL that doesn't exist on a subsequent request). You can kinda-sorta "customize" the Sinja routes by passing in a different symbol, for example resource :testkey
(/testkeys
) instead of resource :test_key
(/test-keys
). Unfortunately, as I described above, there's currently no way to get /testkey
due to the pluralization rule.
from sinja.
Yes, that helped quite a bit for test scenario (I committed my update to reflect that), but unfortunately I think it needs to be done at a deeper level in sinja because it is failing in my application while including a related has_many
resource. In my real use-case, I have GET /users/1?include=apikeys%2Cidentities
(bringing along both apikeys
and identities
), but the response payload doesn't seem to rely on the underlying APIKey's type
instance method when creating the has_many
collection.
I am trying to build an app that relies on your library to implement the {json:api} spec, so I don't know if that makes me an early adopter, but I would certainly appreciate this customization being available. I can successfully POST to /apikeys and create a new key, but subsequently listing a user's keys produces unexpected results. Going from dashes to underscores in a consistent manner across libraries and possible languages is difficult, so being able to explicitly dictate the route would be helpful.
from sinja.
Nothing you've described makes me think you need this feature. Do you have some time to chat with me on Gitter or somewhere else so I can help you work through this use case?
from sinja.
Related Issues (19)
- TODO HOT 1
- Primary key updating broken on JRuby
- All creates yield `Malformed {json:api} request payload` HOT 9
- Custom routes within resource block not working HOT 4
- Issue with Padrino HOT 9
- NoMethodError - undefined method `nullif' HOT 5
- Question about filters HOT 20
- Really slow require of Sinja
- getting Malformed JSON in the request body when request.body is not rewindable HOT 2
- Rewrite error handling as middleware
- Implement Ruby 3 support? HOT 2
- I think you can do this, we will support you
- Add examples and extensions for other DALs and ORMs
- Create Ember demo app
- Document Sequel helpers and extension HOT 1
- Document demo app
- Implement filtering, sorting, and paging
- Generate Swagger documentation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sinja.