Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tips for developing routes and handlers in Reitit #112

Open
practicalli-johnny opened this issue Oct 7, 2022 · 0 comments
Open

Tips for developing routes and handlers in Reitit #112

practicalli-johnny opened this issue Oct 7, 2022 · 0 comments

Comments

@practicalli-johnny
Copy link
Contributor

practicalli-johnny commented Oct 7, 2022

Developing handlers - understanding data involved

Handing request debug technique - return useful information as a separate key, e.g. :dev-info to share useful information in the response to the request

(defn complete-gamer-history
  "Handler function for /gamer/history/complete
  Arguments:
  - environment hash-map containing system configuration
  Returns:
  - Function that takes the ring hash-map of the http request as an argument"
  [environment]
  (fn [request]
    (let [;; Get the Invoice
          gamer (request :body-params)]

      ;; Ring response hash-map
      {:status 200
       :body {:gamer-history (complete-history gamer) 
              :dev-info invoice}
       :headers {}}
      #_())))

The routing with reitit verification and open api keys, which includes the :dev-info key as part of the response

(defn routes
    "Calls `practicalli.gameboard.api.gamer.handlers/complete-gamer-history`
  The handler returns a function that takes the request as an argument"
    [environment]
    ["/gamer" {:swagger {:tag ["Gamer API"]}}
     ["/history"
      ["/complete"
       {:post
        {:summary "Complete Gamer history"
         :description
         "Gather information from all games the Gamer has played"

     ;; parameters used for validation and OpenAPI documentation
         :parameters
         {:body
          {:customer-uuid uuid?
           :email string?
           :first_name string?
           :last_name string?
           :phone_number string?
           :is_existing_customer boolean?
           :ip_address string?
           :billing-address {:street string?
                             :house-number string?
                             :postal_code string?
                             :city string?
                             :country string?
                             :addition string?}
           :games [{:title string?
                    :description string?
                    :software-house string?}]}}

     ;; responses used for validation and OpenAPI documentation
         :responses {200 {:body {:is-fraud boolean?
                             ;; :dev-info used for developer information
                                 :dev-info map?}}
                     400 {:body string?}
                     500 {:body string?}}

         :handler (handlers/complete-gamer-history environment)}}]]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant