What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

Glue Api Versioning: I am trying to implement Versioning for CustomRestAPI. I have created Two ver

U035GSLDLVD
U035GSLDLVD Posts: 90 πŸ§‘πŸ»β€πŸš€ - Cadet
edited September 2022 in Help

Glue Api Versioning:

I am trying to implement Versioning for CustomRestAPI. I have created Two versions version 2 and version 3 TestimonialResourceRouteVersion2Plugin, TestimonialResourceRouteVersion3Plugin and added ResourceVersionableInterface in implement. it has method getVersion function per file as well.

Version2 File:

 public function getVersion(): RestVersionTransfer
    {

        return (new RestVersionTransfer())
            ->setMajor(2)
            ->setMinor(0);
    }

Version3 File:

 public function getVersion(): RestVersionTransfer
    {

        return (new RestVersionTransfer())
            ->setMajor(3)
            ->setMinor(0);
    }

I have added in GlueDependencyProvider file as well. Issue is when I try to request to the data, it always returning Version3 data. I passed version:2.0 in header parameter but it't not retrieving version 2.0 data.
If I pass wrong version number, 4.0 as header param, it should return 404 as well but in my case it's returning version 3.0 data . Seems something is missing.
Any help would be appreciated.

Comments

  • Anila Gjergji
    Anila Gjergji Sprykee Posts: 4 πŸ§‘πŸ»β€πŸš€ - Cadet

    Hi @U035GSLDLVD can you please check some of the configurations:

    1. There are two configs we introduced recently that will allow passing the version in the URL instead of the header:
      Config below should be false for header:
    \Spryker\Glue\GlueApplication\GlueApplicationConfig::getPathVersionResolving 
    

    Config below is not used if the first config is false:

    \Spryker\Glue\GlueApplication\GlueApplicationConfig::getPathVersionPrefix
    
    1. Please check that you are passing the version correct in the header *Content*-*Type*: application/vnd.api+json; version=2.0 .
      If you set it: version:2.0 as you have mentioned, it will not work.

    Also please note that the original plugin (version 1.0) will also need to implement the versionable interface since there will be no way to access it (passing no version in the header will always resolve to the latest version - 3.0)

  • U035GSLDLVD
    U035GSLDLVD Posts: 90 πŸ§‘πŸ»β€πŸš€ - Cadet

    @U033AS56258 Thanks for the help! I looked into this. Yes both functions exist in below file with following return type.

    \Spryker\Glue\GlueApplication\GlueApplicationConfig::getPathVersionResolving =>  return False
    
    \Spryker\Glue\GlueApplication\GlueApplicationConfig::getPathVersionPrefix  => return ''
    

    I have not modified these functions in project specific file:

    Pyz\Glue\GlueApplication\GlueApplicationConfig
    

    Yes, I am passing version correctly. I am using Postman to request the different version but it is always returning the latest version data.

  • U035GSLDLVD
    U035GSLDLVD Posts: 90 πŸ§‘πŸ»β€πŸš€ - Cadet

    Did you mean I need to implement default api as Version 1? then only rest of the versions will work?

  • Anila Gjergji
    Anila Gjergji Sprykee Posts: 4 πŸ§‘πŸ»β€πŸš€ - Cadet

    I got some feedback internally that version 2 vs version 3 should be working as it is, however, will be following up again.

  • Anila Gjergji
    Anila Gjergji Sprykee Posts: 4 πŸ§‘πŸ»β€πŸš€ - Cadet

    I got a confirmation that version 2 and 3 should work without implementing versionable interface for version 1 which is the original plugin

  • U035GSLDLVD
    U035GSLDLVD Posts: 90 πŸ§‘πŸ»β€πŸš€ - Cadet

    Thanks Anila! Appreciate your help! will share what I tried so far.

  • Anila Gjergji
    Anila Gjergji Sprykee Posts: 4 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited September 2022

    I checked it locally and it seems to be a formatting issue (a missing space), and it seems to work as expected Content-Type is:

    application/vnd.api+json; version=3.0
    

    Response: this is third

    application/vnd.api+json; version=2.0
    

    Response: this is second

    application/vnd.api+json; version=4.0
    

    Response:

    {
        "errors": [
            {
                "status": 404,
                "detail": "Not Found"
            }
        ]
    }