Question

I have a java backed web service that i want to test out with ActiveResource.

What are the base assumed url endpoints, say I have a resource for Users.

Currently my url is:

localhost:8080/api/users

I created a test class, and it fails because it assumes I have this url:

localhost:8080/api/users.json

I was planning on doing this:

localhost:8080/api/users/   (GET - lists users)
localhost:8080/api/users/create (POST - create a user)
localhost:8080/api/users/10  (GET user with id 10)
localhost:8080/api/users/10/update (POST - update user with id 10)

What is the Rails standard? Is this standard the 'standard' across other frameworks?

Était-ce utile?

La solution

Rails (and therefore ActiveResource) assume that for every resource (users, posts...) you have available the following endpoints (I excluded the endpoint prefix):

  • GET /users.json to get all of the users
  • GET /users/2.json to get details about user with ID = 2
  • POST /users.json to create a new user
  • DELETE /users/2.json to delete user with ID = 2
  • PUT /users/2.json to update user with ID = 2

You can choose the data format like this:

User.format = :xml
User.find(2) # => GET /users/2.xml

It would probably be best if you create a new Rails app, scaffold the user resource and play with it from console. That way you could also see the data expected data structure.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top