Does Retrofit remove the trailing slash from a relative url for an endpoint?  I have tried adding the trailing slash on one of my endpoints but when i step through with a debugger and i look at the Call object, if I drill into the delete.relativeUrl it does not show the trailing slash.
            Asked
            
        
        
            Active
            
        
            Viewed 3,752 times
        
    3
            
            
         
    
    
        Etienne Lawlor
        
- 6,817
- 18
- 77
- 89
- 
                    For those who end up here accidentally here is pretty good answer for question in subject https://stackoverflow.com/questions/53211672/using-retrofit-to-get-url-from-different-relative-paths – igor.beslic Mar 25 '21 at 21:05
2 Answers
14
            
            
        You need to manually add the slash at the end of the base URL endpoint.
Let's say you have this two instances of retrofit:
No Slash
Retrofit retrofitNoSlash = new Retrofit.Builder()
        .baseUrl("https://example.com/api/v5")
        .build();
- @GET("something"):- https://example.com/api/v5something
- @GET("/something"):- https://example.com/something
With Slash
Retrofit retrofitWithSlash = new Retrofit.Builder()
        .baseUrl("https://example.com/api/v5/")
        .build();
- @GET("something"):- https://example.com/api/v5/something
- @GET("/something"):- https://example.com/something
so: add the trailing slash manually
 
    
    
        OneCricketeer
        
- 179,855
- 19
- 132
- 245
 
    
    
        Daniele Segato
        
- 12,314
- 6
- 62
- 88
0
            
            
        You can try the following code. Just remove slash with base url because back slash already added begin with end point url in GET method.
NetworkInterface.java
@GET("/baking.json")
Call<List<ResponseModel>> getRecepies();
public static Retrofit retrofit = new Retrofit.Builder()
    .baseUrl(URLs.RECEPIES_URL)
    .addConverterFactory(GsonConverterFactory.create())
    .build();
URLs.java
  public static String RECEPIES_URL="https://d17h27t6h515a5.cloudfront.net/topher/2017/May/5907926b_baking";
 
    
    
        Sathish Kumar VG
        
- 2,154
- 1
- 12
- 19