Skip to content

Making router agnostic about making urls

Compare
Choose a tag to compare
@thetutlage thetutlage released this 28 Jul 10:44

Earlier the router was generating fully qualified URLS for a given domain. Instead, now it becomes agnostic about it and instead exposes the API to lookup routes and a helper method to make url from the looked up route.

Earlier

router.get('/posts/:id', handler).domain('blog.adonisjs.com')
router.makeUrl('/posts/:id', { params: { id: 1 } })

// returns: //blog.adonisjs.com/posts/1

Now

import { makeUrl } from '@poppinss/http-server'

const route = router.lookup('/posts/:id')
makeUrl(route.pattern, { params: { id: 1 } })

// returns /posts/1

With the newer API you can decide

  • If you want to append a domain or not.
  • Decide which protocol to use

Commits

  • refactor(router): making router agnostic about making urls 0d809f6
  • chore: update request package 358f136
  • refactor: eargerload exception handler 4ecb513
  • chore(package): update dependencies 27b8ec8

v1.1.8...v1.2.0