• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Generic route for options on ERXRest
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Generic route for options on ERXRest


  • Subject: Re: Generic route for options on ERXRest
  • From: Flavio Donadio <email@hidden>
  • Date: Wed, 27 Jul 2016 13:13:37 -0300

Luiz,


I am confused by your post.

When you say "if a have an API to list all of the entries of a specific table, then I have a route like 'myURL/listAllEntries’”, it seems strange. You don’t need to create a route for that; you can just call ERXRouteRequestHandler.addDefaultRoutes() for each of you entities, like:

public Application() {
	// app initialization code…

	// create
	setDefaultRequestHandler(requestHandlerForKey(directActionRequestHandlerKey()));
	ERXRouteRequestHandler routeRequestHandler = new ERXRouteRequestHandler(ERXRouteRequestHandler.WO);

	// automagically create RESTful routes for you entities
	routeRequestHandler.addDefaultRoutes(YourEntityClass.ENTITY_NAME);
	routeRequestHandler.addDefaultRoutes(YourOtherEntityClass.ENTITY_NAME);
	// …

	// finally, register your route request handler
	ERXRouteRequestHandler.register(routeRequestHandler);
}

This will create all basic “CRUD" routes for you. You only need to declare "non-standard" routes, and only if needed. You’ll have all your entries listed when  http://myAppUrl/myEntityName is requested through the GET HTTP verb. If you POST to http://myAppUrl/myEntityName, you create an entry. If you GET http://myAppUrl/myEntityName/id you’ll get the individual item. It’s as simple as that! You can even specify the format you want the data through an extension, like http://myAppUrl/person/6.json.

Now that we have that cleared up...

… I assume you solved the first part of your optionsAction() problem: you subclassed ERXRouteController and implemented the optionsAction() method there, then made all your entity route controllers inherit from that class. Now, what I think would be the simplest thing to do for adding and registering your routes would be to loop through your model entityNames property (it’s an array) in your app initialization… It’s easy and keeps all your route addition code in one place.

I recommend you take a look at this tutorial (and ignore the SproutCore parts):

	https://wiki.wocommunity.org/display/documentation/SproutCore+and+ERRest

This presentation is very nice, too:

	http://wocommunity.org/podcasts/ERRest-2010-02-16.mov


Regards,
Flavio

> On 26/07/2016, at 13:33, Luiz Alfredo Carrara Bertusso <email@hidden> wrote:
>
> Hello developers, I've been facing a doubt about creating routes for a Rest API using ERXRest.
> In the Application I've been working there some APIs for different purposes, but all of them need to access the method "optionsAction()".
> I have an implementation of this method on an abstract class and all of the APIs extends it, so here comes the problem, for each API I have to create an individual route to access this method.
> For example, if a have an API to list all of the entries of a specific table, then I have a route like "myURL/listAllEntries", until now it`s ok, but let me say if I want an specific entry of that table then I have to create another route like "myURL/listAllEntries/{wantedID}", it`s fine for the use of the API, but I've been heaving to create the same routes indicating the options method for all possible routes I have to crete. So I have duplicates routes for CRUD methods, but at the same time I have to do it for the options method.
> Is there a way I could creste an abstract route that could cover all of the existing APIs? Something like an universal route for options method?
> Thank you.
> _______________________________________________
> 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


 _______________________________________________
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


References: 
 >Generic route for options on ERXRest (From: Luiz Alfredo Carrara Bertusso <email@hidden>)

  • Prev by Date: Re: Generic route for options on ERXRest
  • Next by Date: WOlips and Windows
  • Previous by thread: Re: Generic route for options on ERXRest
  • Next by thread: WOlips and Windows
  • Index(es):
    • Date
    • Thread