RESTAS:GENURL for mounted modules

43 views
Skip to first unread message

Mark Evenson

unread,
Mar 27, 2014, 1:06:44 PM3/27/14
to res...@googlegroups.com
I'm developing a REST API for RESTAS, trying to segregate functionally related parts in RESTAS modules.

I would like the "top-level" module to provide an navigable interface to its mounted modules computed from URL upon which these modules are mounted. 

The problem I am running into is that RESTAS:GENURL (or RESTAS:GENURL*) doesn't  include the path that the module is mounted on, nor can I see an easy way to concatenate things based on the package and symbol that designates a RESTAS:DEFINE-ROUTE.

Is there a way I can get the path upon which a module is mounted somehow included in dynamic URL generation?

(restas:define-module #:rest.index (:use #:cl)) ;; the top-level index of the API

(restas:define-module #:rest.scan (:use #:cl)) ;; a sub-module to mount in the API

(in-package #:rest.scan)

(restas:define-route %index ("")
  (who:with-html-output-to-string (o)
    (:html
     (:body
      (:p "Index of scan API")))))

(in-package #:rest.index)

(restas:define-route %index ("")
  (who:with-html-output-to-string (o)
    (:html
     (:body
      (:h1 "Scanned Documents API")
      (:p ((:a :href "/scan/" ;;  (restas:genurl 'rest.scan::%index) --> "/".  I want to somehow generate "/scan/" from the symbol
               )
           "INDEX"))))))

(restas:mount-module -scan- (#:rest.scan) 
  (:url "/scan/"))

#|
(restas:start '#:rest.index)
|#

Orivej Desh

unread,
Mar 27, 2014, 2:16:43 PM3/27/14
to res...@googlegroups.com
Since a module can be mounted multiple times, its routes may correspond to different URLs.

To get the URL part of '-scan- in rest.index, you may use
(first (restas::module-mount-url (restas:find-mounted-module '-scan-)))
It will be "scan" because surrounding slashes were stripped when the module was mounted.

Andrey Moskvitin

unread,
Mar 27, 2014, 2:54:58 PM3/27/14
to res...@googlegroups.com
Hi,

> Since a module can be mounted multiple times, its routes may
> correspond to different URLs.

When a module mounted RESTAS creates special symbols for its routes.

Use

(restas:genurl '-scan-.%index)

instead of

(restas:genurl 'rest.scan::%index)


Andrey
> --
> You received this message because you are subscribed to the Google Groups "restas" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to restas+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Mark Evenson

unread,
Mar 28, 2014, 11:09:32 AM3/28/14
to res...@googlegroups.com


On Thursday, March 27, 2014 7:54:58 PM UTC+1, archimag wrote:

[…]

When a module mounted RESTAS creates special symbols for its routes.

Use

(restas:genurl '-scan-.%index)

Works great!  Thanks again for RESTAS.
Reply all
Reply to author
Forward
0 new messages