Questions tagged [compojure-api]

Stuff on top of Compojure for making sweet web apis.

You can read more about it at https://github.com/metosin/compojure-api

51 questions
14
votes
2 answers

Optional query parameters (with default value) with compojure-api

What is the proper way to declare an optional query parameter, with default value, when using compojure-api? One of my route elements is as follows (after reading this): (GET "/:id/descendants" [id] :return [d/CategoryTreeElement] …
Matheus Moreira
  • 2,338
  • 4
  • 24
  • 31
8
votes
1 answer

:body-params vs :form-params in compojure-api

What's the difference between using :body-params and :form-params in practice when creating an API using compojure-api? For example: (POST* "/register" [] :body-params [username :- String, password :- String] …
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
6
votes
1 answer

why are compojure routes defined as macros?

for example the Luminus website states that Compojure route definitions are just functions that accept request maps and return response maps... (GET "/" [] "Show something") ... But compojure routes are not functions (defmacro GET "Generate a…
beoliver
  • 5,579
  • 5
  • 36
  • 72
6
votes
1 answer

Non-required arguments in compojure-api/schema/swagger?

When I have a definition of an API like this: (POST* "/register" [] :body-params [username :- String, password :- String, name :- String] (ok))) what's the appropriate way of making name optional? Is…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
4
votes
1 answer

lein ring uberjar -- java.lang.NoClassDefFoundError: clojure/lang/Var

Not certain why when I lein with-profile +live ring uberjar and then java -jar my uberjar, I get this exception: java.lang.NoClassDefFoundError: clojure/lang/Var. project.clj: (defproject gn-preview-api "0.1.0-SNAPSHOT" :description "FIXME: write…
Micah
  • 10,295
  • 13
  • 66
  • 95
4
votes
3 answers

Clojure, Compojure-api: Access Request headers

I am trying to implement request end point authentication. For that I want to access accessToken value from request headers. My GET request end Point is CURL Command curl -X GET \ 'http://localhost:3000/hello?id=10' \ -H 'accesskey:…
Srini
  • 823
  • 5
  • 10
  • 29
4
votes
2 answers

How do I make a literal function that takes no args and return a constant value?

I'm trying to learn Clojure, and am blocked up around the literal function syntax. I can't figure out what the literal function equivalent of (defn fourteen [] 14) is. (def fourteen (fn [] 14)) ;; => #'user/fourteen (fourteen) ;; => 14 (defn…
Bob Kuhar
  • 10,838
  • 11
  • 62
  • 115
3
votes
0 answers

How to implement middleware for Swagger in compojure-api for converting schemas from kabab-case to camelCase

Application uses kabab-case key formatting for schema like below (s/defschema User {:first-name s/Str :last-name s/Str}) But for swagger docs I want the schema in camelCase like…
Abhishek Jaiswal
  • 628
  • 6
  • 17
3
votes
1 answer

How do I add CORS to a compojure-api app?

How can I add CORS to this code snippet? (def app (api {:swagger {:ui "/docs" :spec "/swagger.json"}} (GET "/route-a" [] "a") (GET "/route-b" [] "b") (GET "/route-c" [] "c"))) I would like to…
Freid001
  • 2,580
  • 3
  • 29
  • 60
3
votes
0 answers

Clojure, Compojure: How Can I add Ring middleware CORS to ring adapter jetty based project?

I am using ring adapter jetty server in my compojure api project. Now I want to add ring middleware CORS to my Project. How should I add and where should I add ring middleware CORS in my project? These are my project code snippets API (ns…
Srini
  • 823
  • 5
  • 10
  • 29
3
votes
2 answers

How can I explicitly set content type on compojure response?

I am playing with compojure-api and am blocked at trying to manage Content-Type for my simple webapp. What I want is to emit an HTTP response that is just plain/text, but somehow Compojure-API keeps setting it to "application/json". (POST…
Bob Kuhar
  • 10,838
  • 11
  • 62
  • 115
3
votes
1 answer

What is the difference between body and body-params in compojure-api?

In compojure-api I noticed this two ways of specifying the API of a resource: (POST* "/register" [] :body [user UserRegistration] (ok))) and (POST* "/register" [] :body-params [username :- String, password :- String] …
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
2
votes
1 answer

Can not execute middleware if using a exception handler?

wrap-cors does not return access control headers when there is a bad request against my api endpoint. I believe this is because I am using a exception handler which might be blocking the middleware from running. I want to know how I can still…
Freid001
  • 2,580
  • 3
  • 29
  • 60
2
votes
0 answers

Async Compojure-Api Middleware not Working

My middleware is throwing an error only for async requests, not sure why: project.clj (defproject asyncy "0.1.0-SNAPSHOT" :description "FIXME: write description" :dependencies [[org.clojure/clojure "1.9.0"] …
Micah
  • 10,295
  • 13
  • 66
  • 95
2
votes
1 answer

I cant get compojure-api to correctly validate bad data for a query-parameter with an Inst schema

Here, I am using the metosin/compojure-api library, to configured a GET /fetch endpoint for my api. You will see that I am also using plumatic/schema to validate the query-parameter inputs on this endpoint and siilisolutions/humanize to humanise any…
Freid001
  • 2,580
  • 3
  • 29
  • 60
1
2 3 4