79223922

Date: 2024-11-25 16:52:39
Score: 0.5
Natty:
Report link

Like @johanandren suggested, I replaced all except the last path with pathPrefix.

And the code now works!

The Routes code now looks like below:

(Disclaimer: Llama or ChatGPT could NOT have pulled off this beautiful solution in a million years!!! God given natural intuition still rocks! 😎😎😎👌👌👌)


  val schoolRoutes: Route =
    pathPrefix("littlerock") {
    concat(

    pathPrefix("admins") {
      concat(
        pathEnd {
          concat(
            get {
              complete("District administrators.")
            })
        })
    },

    pathPrefix("schools") {
      concat(
        pathPrefix(Segment) { name =>
          concat(
            pathEnd {
            get {
              rejectEmptyResponse {
                  complete("A school's details.")
              }
            }
            },
            pathPrefix("students") {
              concat(
                pathEnd {
                  get {
                    rejectEmptyResponse {
                      complete("All students")
                    }
                  }
                },
                pathPrefix(Segment) { studentName =>
                  concat(
                    pathEnd {
                    get {
                      rejectEmptyResponse {
                        complete("A student's details")
                      }
                    }},
                    pathPrefix("classmates") {
                      concat(
                        pathEnd {
                          get {
                            rejectEmptyResponse {
                              complete("A student's classmates.")
                            }
                          }
                        },
                        path(Segment) { classmateName =>
                          concat(
                            get {
                              rejectEmptyResponse {
                                complete("A classmate's details.")
                              }
                          })
                        }
                      )
                    }
                  )
                }
              )
            }
          )
      })
    }
  )}

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @johanandren
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Vakindu