Custom response header Jersey/Java

I think using javax.ws.rs.core.Response is more elegant and it is a part of Jersey. Just to extend previous answer, here is a simple example: @GET @Produces({ MediaType.APPLICATION_JSON }) @Path(“/values”) public Response getValues(String body) { //Prepare your entity Response response = Response.status(200). entity(yourEntity). header(“yourHeaderName”, “yourHeaderValue”).build(); return response; }

Using plus sign in custom internet media types (MIME types)

The procedure for registering new suffixes is now defined in http://trac.tools.ietf.org/html/draft-ietf-appsawg-media-type-regs-14#section-6. “+json” will be defined in a separate document; right now: http://trac.tools.ietf.org/html/draft-ietf-appsawg-media-type-suffix-regs-02#section-3.1 And no, you are not supposed to have multiple subtypes there.

Is HTTP status code 426 Upgrade Required only meant signal an upgrade to a secure channel is required?

Quoting one of my previous answers: HTTP Upgrade is used to indicate a preference or requirement to switch to a different version of HTTP or to another protocol, if possible: The Upgrade general-header allows the client to specify what additional communication protocols it supports and would like to use if the server finds it appropriate … Read more

pytest assert message customization with variable introspection

you could use Python built-in capability to show custom exception message: assert response.status_code == 200, f”My custom msg: actual status code {response.status_code}” Or you can built a helper assert functions: def assert_status(response, status=200): # you can assert other status codes too assert response.status_code == status, \ f”Expected {status}. Actual status {response.status_code}. Response text {response.text}” # … Read more

Add Serializer on Reverse Relationship – Django Rest Framework

Ahmed Hosny was correct in his answer. It required the many parameter to be set to True to work. So final version of the CartSerializer looked like this: class CartSerializer(serializers.ModelSerializer): cartitem_set = CartItemSerializer(read_only=True, many=True) # many=True is required class Meta: model = Cart depth = 1 fields = ( ‘id’, ‘date_created’, ‘voucher’, ‘carrier’, ‘currency’, ‘cartitem_set’, … Read more

Is 502 an appropriate status code for a database error?

No, I don’t think an HTTP 502 Bad Gateway error is appropriate when a database error occurs. HTTP errors say something about the HTTP protocol. This specific error indicates a server is trying to relay the HTTP request, but the upstream server did not respond correctly. Your web application communicating with a database server is … Read more

How to set and check cookies wih JAX-RS?

You can do the following: To store a new cookie: @GET @Path(“/login”) @Produces(MediaType.TEXT_PLAIN) public Response login() { NewCookie cookie = new NewCookie(“name”, “123”); return Response.ok(“OK”).cookie(cookie).build(); } To retrieve the cookie (javax.ws.rs.core.Cookie): @GET @Path(“/foo”) @Produces(MediaType.TEXT_PLAIN) public Response foo(@CookieParam(“name”) Cookie cookie) { if (cookie == null) { return Response.serverError().entity(“ERROR”).build(); } else { return Response.ok(cookie.getValue()).build(); } } However, … Read more

RESTful v/s MQ. Differences and other key features apart from Guaranteed Delivery

One of the biggest differences is that REST implies synchronous processing while MQ is more often asynchronous. As you already mentioned, MQ is a way to decouple producer and consumer so that they don’t have to be online at the same time but the system would still be functioning as a whole. If your use … Read more

tech