Talk about the REST API of Eureka Server

sequence

This article mainly studies the REST API of Eureka Server

ApplicationsResource

eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/ApplicationsResource.java

@Path("/{version}/apps")
@Produces({"application/xml", "application/json"})
public class ApplicationsResource {
	@Path("{appId}")
    public ApplicationResource getApplicationResource(
            @PathParam("version") String version,
            @PathParam("appId") String appId) {
        CurrentRequestVersion.set(Version.toEnum(version));
        return new ApplicationResource(appId, serverConfig, registry);
    }

    //...
    @GET
    public Response getContainers(@PathParam("version") String version,
                                  @HeaderParam(HEADER_ACCEPT) String acceptHeader,
                                  @HeaderParam(HEADER_ACCEPT_ENCODING) String acceptEncoding,
                                  @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept,
                                  @Context UriInfo uriInfo,
                                  @Nullable @QueryParam("regions") String regionsStr) {
                                  //...
    }

    @Path("delta")
    @GET
    public Response getContainerDifferential(
            @PathParam("version") String version,
            @HeaderParam(HEADER_ACCEPT) String acceptHeader,
            @HeaderParam(HEADER_ACCEPT_ENCODING) String acceptEncoding,
            @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept,
            @Context UriInfo uriInfo, @Nullable @QueryParam("regions") String regionsStr) { 
            //...
    }                                     

}

Three interfaces are provided here:

  • /{version}/apps/{appId}
  • /{version}/apps
  • /{version}/apps/delta

For spring cloud eureka, the version here is eureka

ApplicationResource

eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/ApplicationResource.java

    @GET
    public Response getApplication(@PathParam("version") String version,
                                   @HeaderParam("Accept") final String acceptHeader,
                                   @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept) {
                                   //...
    } 

    @Path("{id}")
    public InstanceResource getInstanceInfo(@PathParam("id") String id) {
        return new InstanceResource(this, id, serverConfig, registry);
    }        

    @POST
    @Consumes({"application/json", "application/xml"})
    public Response addInstance(InstanceInfo info,
                                @HeaderParam(PeerEurekaNode.HEADER_REPLICATION) String isReplication) {
                                //...
    }                                                  

Three interfaces are provided here

  • /{version}
  • /{id}
  • POST /

InstancesResource

eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/InstancesResource.java

@Produces({"application/xml", "application/json"})
@Path("/{version}/instances")
public class InstancesResource {
	@GET
    @Path("{id}")
    public Response getById(@PathParam("version") String version,
                            @PathParam("id") String id) {
                            //...
    }


}

Here is an interface

  • /{version}/instances/{id}

StatusResource

eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/StatusResource.java

@Path("/{version}/status")
@Produces({"application/xml", "application/json"})
public class StatusResource {
	@GET
    public StatusInfo getStatusInfo() {
        return statusUtil.getStatusInfo();
    }
    //...
}

Here's an excuse

  • /{version}/status

VIPResource

eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/VIPResource.java

@Path("/{version}/vips")
@Produces({"application/xml", "application/json"})
public class VIPResource extends AbstractVIPResource {
    @GET
    @Path("{vipAddress}")
    public Response statusUpdate(@PathParam("version") String version,
                                 @PathParam("vipAddress") String vipAddress,
                                 @HeaderParam("Accept") final String acceptHeader,
                                 @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept) {
        return getVipResponse(version, vipAddress, acceptHeader,
                EurekaAccept.fromString(eurekaAccept), Key.EntityType.VIP);
    }
}

Here's an excuse

  • /{version}/vips/{vipAddress}

SecureVIPResource

eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/SecureVIPResource.java

@Path("/{version}/svips")
@Produces({"application/xml", "application/json"})
public class SecureVIPResource extends AbstractVIPResource {
    @GET
    @Path("{svipAddress}")
    public Response statusUpdate(@PathParam("version") String version,
                                 @PathParam("svipAddress") String svipAddress,
                                 @HeaderParam("Accept") final String acceptHeader,
                                 @HeaderParam(EurekaAccept.HTTP_X_EUREKA_ACCEPT) String eurekaAccept) {
        return getVipResponse(version, svipAddress, acceptHeader,
                EurekaAccept.fromString(eurekaAccept), Key.EntityType.SVIP);
    }
}

Here's an excuse

  • /{version}/svips/{svipAddress}

PeerReplicationResource

eureka-core-1.8.8-sources.jar!/com/netflix/eureka/resources/PeerReplicationResource.java

@Path("/{version}/peerreplication")
@Produces({"application/xml", "application/json"})
public class PeerReplicationResource {
    @Path("batch")
    @POST
    public Response batchReplication(ReplicationList replicationList) {
    	//....
    }
}

Here is an interface

  • POST /{version}/peerreplication/batch

summary

The rest api of eureka server is implemented using javax.ws. Then the version of spring cloud, its version passes the eureka value. The interface implemented by javax.ws feels that it is very difficult to find a mapping compared to spring mvc, and it is a little bit laborious.

doc

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325482760&siteId=291194637