Home > Software design >  Changing endpoint but want to keep old endpoint
Changing endpoint but want to keep old endpoint

Time:11-19

We have some endpoints that we want to change but still want to keep using old ones for some time.

Example: Current Endpoint: /download -> New Endpoint: /document/download. We want to use both.

The Endpoints are defined in a class. Current:

class Endpoints {
  public static final DOCUMENT_HOME = "/home";
  public static final DOWNLOAD = "/download";
}

@RequestMapping(Endpoints.DOCUMENT_HOME)
class DocumentController {
  @GetMapping(value = Endpoints.DOWNLOAD)
  public void download();
}

New:

class Endpoints {
  public static final DOCUMENT_HOME = "/home/document";
  public static final DOWNLOAD = "/download";
}

@RequestMapping(Endpoints.DOCUMENT_HOME)
class DocumentController {
  @GetMapping(value = Endpoints.DOWNLOAD)
  public void download();
}

CodePudding user response:

If you want to use both endpoints then write code like this.



class Endpoints {
  public static final DOCUMENT_HOME = "/home";
  public static final DOWNLOAD = "/download";
  public static final DOCUMENT = “/document”;
}

@RequestMapping(Endpoints.DOCUMENT_HOME)
class DocumentController {
  @GetMapping(value = Endpoints.DOWNLOAD)
  public void downloadV1();

   @GetMapping(value = Endpoints.DOCUMENT   Endpoints.DOWNLOAD)
  public void downloadV2();

  
}

CodePudding user response:

I don't know how meaningful your request is, but you can use it by doing something like this.

@GetMapping({"/public/v1/oldEndPoint/{id}", "/private/v1/newEndPoint/{id}"})
  • Related