REST API having same object, but light - api

We are building a REST API and we want to return the same object, but one call is a 'light' version (without all the field)
what is the best practice ?
1st case
full version: http://api.domain.com/myobject/{objectId}
light version: http://api.domain.com/myobject/{objectId}?filter=light
2nd case
full version: http://api.domain.com/myobject/{objectId}/details
light version: http://api.domain.com/myobject/{objectId}
3rd case
full version: http://api.domain.com/myobject/{objectId}?full=true
light version: http://api.domain.com/myobject/{objectId}
4th case ?
Any link to a documented resource of a REST API is welcome !
Thanks.

This should be handled through content negotiation, that's what its for. Content negotiation is how a client can request which representation of the resource it wants to see. Consider the case of a picture: image/x-canon-cr2, image/jpeg, image/png.
Ostensibly all the same image, but in different formats.
So, this is the mechanism you really want to use for a "lite" version of your resource. For example you could use:
"application/xhtml+xml" for the main version
"application/xhtml+xml; lite" for the for the light weight version
So, for a full resource:
GET /resource
Accept: application/xhtml+xml
For a light version
GET /resource
Accept: application/xhtml+xml; lite
For either, but preferring the lite version:
GET /resource
Accept: application/xhtml+xml;lite, application/xhtml+xml
(the more specific specifier, i.e. the one with ;lite, has higher priority over the normal applciation/xhtml+xml.)
If you will take either, but prefer the full version:
GET /resource
Accept: application/xhtml+xml;lite;q=0.1, application/xhtml+xml
Those without a quality factor default to 1.0, so 0.1 is less than 1.0 and you will get the full version if available over the lite version.
Addenda:
The q factor on Accept is effectively used to show the preferences of the client. It is used to prioritize the list of media types that the client accepts. It says "I can handle these media types, but I prefer a over and b over c".
A JPEG vs a PNG is no different than the lite vs full version. The fact that a JPEG looks anything like the original PNG is an optical illusion, the data is far different, and they have different uses. A JPEG is not "lower quality", it's different data. It's "missing fields". If I want, say, the image size, the JPEG will give me that information just as well as a PNG would. In that case, it's quality is adequate for the task. If it wasn't adequate, then I shouldn't be requesting it.
I can guarantee that if I have a client that can only process PNG and ask for a JPEG, then that program will not "work equally well" with it. If my son wants Chicken Fingers and I give him Cream of Spinach, there are going to be issues, even though both of those are representations of the the resource /dinner.
The "application/xhtml+xml;lite" representation is just that -- a representation, it is NOT the resource itself. That's why the word representation is used. The representations are all simply projections from the actual resource, which is some virtual entity on the server realized internally in some undefined way.
Some representations are normative, some are not.
Representations are manifested through media types, and media types are handled via Con-neg and the ACCEPT header. If you can't handle a representation, then don't ask for it.
This is a con-neg problem.
I don't know what a "media player" has to do with this discussion.

The 1st case and 3rd case have the advantage that one url is used for a single resource and the query string is used to request a particular view of that resource. Choosing between them is a matter of taste, but I tend to prefer a default of getting all the data and saving the options for viewing subsets.

Related

iText 7 pdfSweep and JPX encoded composite image (MRC compressed PDF)

I have a MRC compressed PDF (images are JPX encoded) which I can not get redacted with iText 7 pdfSweep as the ImageReadException is thrown.
Caused by: org.apache.commons.imaging.ImageReadException: Can't parse this format.
at org.apache.commons.imaging.Imaging.getImageParser(Imaging.java:731)
at org.apache.commons.imaging.Imaging.getImageInfo(Imaging.java:703)
at org.apache.commons.imaging.Imaging.getImageInfo(Imaging.java:637)
at com.itextpdf.pdfcleanup.PdfCleanUpFilter.processImage(PdfCleanUpFilter.java:343)
... 13 more
Do you know any workaround or solution for this issue? An obvious workaround would be to replace the jp2 (jpx) in the PDF with some other image format and perform the redaction on this modified PDF, however, in this case the benefits of MRC compression are lost, not to mention the overall speed of such conversion and then redaction.
(iText developer here)
As you can see, iText uses org.apache.commons to handle the images.
In the past we have had some problems with known bugs in this external library.
A possible solution is to fork the org.apache.commons project, implement a fix, and submit your pull request.
This way, everyone benefits, and the change would automatically be included in iText as well.
Of course, should you be a paying customer, then reporting this problem through the iText support board might trigger us to do the pull request instead.
As for a workaround, I think you've already suggest the appropriate idea.
process all images
convert them to a different format (if needed)
feed the modified document into pdfSweep
More detailed (step 1 and 2)
using IEventListener you can obtain the underlying BufferedImage of a given resource, and you can then use a ByteArrayOutputStream and ImageIO to re-encode your image into standard jpg or png. You can then use iText to change the dictionary entry for this particular resource.

Differences and meanings between gzip header "1f8b0800000000000000" and "1f8b0800000000000003"

As stated in the topic, I am deflating data in my iOS and Android app respectively. The result generated happens to be mostly identical, except that the headers are different.
In iOS, the header is
1f8b0800000000000003
while on Android, the header is
1f8b0800000000000000
Other than this, the remaining parts are identical, I tried to search with both header string but only found results that stating both of them are gzip headers. What are their differences and what would be the possible reason causing them?
Thanks!
GZIP format spec (RFC 1952) says that GZIP member header stores the OS on which the conversion took place, with the intent of describing the filesystem. That's field OS here
http://www.zlib.org/rfc-gzip.html#header-trailer
+---+---+---+---+---+---+---+---+---+---+
|ID1|ID2|CM |FLG| MTIME |XFL|OS | (more-->)
+---+---+---+---+---+---+---+---+---+---+
which matches the position in which you observe the difference.
0 stands for OS with FAT filesystem, 3 stands for Unix.
Granted, trying to identify filesystem through identifying OS does not sound like a good idea today, but that's the way it was originally designed.

Are file extensions required to correctly serve web content?

We're using Amazon S3 to store and serve images, videos, etc. When uploading this content we also always set the correct content-type (image/jpeg, etc.).
My question is this: Is a file extension required (or recommended) with this sort of setup? In other words, will I potentially run into any problems by naming an image "example" versus "example.jpg"?
I haven't seen any issues with doing this in my tests, but wanted to make sure there are any exceptions that I may be missing.
Extensions are just a means by which OS decides the operating program. As far as your scenario is concerned, as long as the content-type specifies the type, the extension doesn't matter. But why in the world, would you name a jpg file as .txt right ?
Regards

can XInclude be used on stream input?

I would like a portable solution to creating a multiply nested XML document using XInclude. I am using <xi:include href="foo.xml"> elements and taking the input from a stream. So far this fails (I am using XOM which has its own XIncluder) which reports it cannot find the base URL for the href. I am wondering if this is a general problem (see XercesDOMParser and XIncludes ). If so are there general workarounds?
A relative URI like foo.xml is useless without the context of a base URI with which to work out that e.g. if the base URI is http://example.net/bar/baz.xml then the absolute URI of the resource is http://example.net/bar/foo.xml.
This base URI can come from:
The URI that the XML in question came from (clearly not applicable to a stream alone).
A URI passed to a parser by mechanisms specific to it.
xml:base
Means specific to a given XML application (not advisable, but sometimes necessary for compatibility with other formats, e.g. the <base /> element in XHTML duplicates xml:base unnecessarily and with less flexibility, but is required for compatibility with HTML4.01 and earlier).

How to get metadata from video-movie file using Objective-c?

Any help? Now can get NSSize, duration and its all.
You can do this almost entirely using Spotlight's metadata.
For example, I do the following in one of my apps
MDItemRef fileMetadata=MDItemCreate(NULL,(CFStringRef)eachPath);
NSDictionary *metadataDictionary = (NSDictionary*)MDItemCopyAttributes (fileMetadata,
(CFArrayRef)[NSArray arrayWithObjects:(id)kMDItemPixelHeight,(id)kMDItemPixelWidth,nil]);
This code essentially asks for the pixel width and height for a movie file (to determine if it's the dimension of an HD movie or not is the reason).
The Spotlight Metadata Attributes Reference lists all the available keys for various file types by category. You can probably get the required data this way without doing anything significant, provided that the media type you're examining has a Spotlight plug-in.
This functionality may not be built in (I'm honestly not sure), but I do know of two third-party libraries which can tell you the information you need.
VLCKit, the framework being used by the newest beta versions of VLC for Mac.
libmediainfo, a multi-purpose library that can read practically any bit of information you need out of practically any media file.
I can go into more depth with how to use either of these, but I'd rather only do so if you end up needing me to. Let me know!