Re: getting to know Mr. ERXRoute
Re: getting to know Mr. ERXRoute
- Subject: Re: getting to know Mr. ERXRoute
- From: Pascal Robert <email@hidden>
- Date: Wed, 29 Dec 2010 21:34:58 -0500
Le 2010-12-29 à 19:10, Jesse Tayler a écrit :
> I'm just getting to know Mr. ERXRoute - very nice fellow - and I ran into some likely simple questions of approach, in what must be a typical situation
>
> I added a route that would return user info based on username which I got working fine:
>
> routeRequestHandler.addRoute(new ERXRoute(User.ENTITY_NAME, "/u/{username:String}", ERXRoute.Method.Get, UserController.class, "username"));
>
> but now I wonder about approach for things like creating a new post for a specific user - not sure if it's easier to pass along a user/pass or work on authentication - I figured I could write a new route method like this:
>
> routeRequestHandler.addRoute(new ERXRoute(User.ENTITY_NAME, "/u/MakePost", ERXRoute.Method.Post, UserController.class, "createPost"));
>
> to which I figured I could say:
>
> curl -X POST -d "{ title:'New Post'; username:'demo'; password:'d';}" http://10.0.1.3:5999/cgi-bin/WebObjects/WOMan.woa/ra/MakePost.json
>
> but this runs into exception during the init method of the post, I had set the author and assignee to the session user in the eo init like so:
>
> setAssigneeRelationship((User) ((User)ERCoreBusinessLogic.actor()).localInstanceIn(editingContext()));
>
> which of course, raises because there's no core business user while I'm calling from curl right?
>
> so, if someone with some more experience setting up ERRest would kindly guide me on these few steps, I'd be much obliged!
You are making it harder that it should :-) If a "Post" is a EO etablished as a relationship to User, you don't need to create custom routes to create related objects. Check the Movies and ERRestRouteExample from Wonder for good examples of how to implement routes.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden