Git Product home page Git Product logo

Comments (12)

AnthonyMDev avatar AnthonyMDev commented on July 24, 2024

0.7.0-beta.2 includes a simple data response serializer that parses Amazon S3 Errors.

I'd like to add serializers for custom ACL responses and custom serializers for common data types that parse AmazonS3Errors.

from amazons3requestmanager.

sebromero avatar sebromero commented on July 24, 2024

I'd like to work on this since I desperately need this functionality. Which branch should I use as a starting point? And one concern: An extension on the Request class as you did seems a plausible way to achieve that. However, If we do that, we will have to call the dedicated serialiser method on the completed request depending on the return type. Like request.responseS3ListData(…), request.responseS3MeataData(…) etc. How about we create subclasses of Request like ListRequest and override either response or a dedicated property like s3response. Like this on the usage side we can ensure that the correct serializer is called. Let me know what you think.

from amazons3requestmanager.

AnthonyMDev avatar AnthonyMDev commented on July 24, 2024

@sbhklr I see what you are going for, however I think that we should still with the custom serializer methods. There may be instances where the user does want to get the raw response data, or serialize it in a different way. By overriding response(), we take away that capability.

This is the method that Alamofire recommends and supports. Subclassing Request may lead to incompatibility issues in later versions of Alamofire.

@cnoon: What are your thoughts on subclassing Request vs. creating custom serializers? Do you see this causing other unintended consequences?

from amazons3requestmanager.

sebromero avatar sebromero commented on July 24, 2024

@AnthonyMDev I see your point but instead of overriding response() we could still create subclasses and override a custom property like s3response. This should be safe. The problem there is that it's probably hard to find a function signature for s3response that suits all use cases. For example listBucket() should return a list of filenames while getObject() should return data. The advantage with the current approach is that adding serializers doesn't break API compatibility with version 1.0.

from amazons3requestmanager.

AnthonyMDev avatar AnthonyMDev commented on July 24, 2024

@sbhklr I do see why that makes things more elegant.

Here's another thing to consider, when using the AmazonS3RequestSerializer to create NSURLRequests but not using the AmazonS3RequestManager, you can send these requests to a regular Alamofire.Manager (or any other networking library for that matter). Using the default Alamofire.ManagerΒ won't return our Request subclass, but I'd still like users to be able to serialize the response using our custom serializers.

What if we created custom serializers, and also created custom Request subclasses. On our subclasses, we can create a new func for s3Response that uses the custom serializers. The AmazonS3RequestManager can return our new subclasses, while still allowing regular old Request objects to also use the custom serializers.

With this approach we maintain the flexibility of custom serializers while giving the elegant API that you are seeking as well.

from amazons3requestmanager.

sebromero avatar sebromero commented on July 24, 2024

Sounds reasonable. I'll give that a try tomorrow.

from amazons3requestmanager.

AnthonyMDev avatar AnthonyMDev commented on July 24, 2024

@sbhklr Thanks for taking this on!

from amazons3requestmanager.

cnoon avatar cnoon commented on July 24, 2024

Hey @AnthonyMDev, definitely don't subclass. You can't anyways b/c the init methods on a Request are internal. You wouldn't be able to make a subclass instance with Alamofire even if you wanted to unless you made some much bigger changes to Alamofire itself. Instead, use the extension approach and add a custom serializer.

In order to mitigate the need for multiple serializers, you could always pass an enum case into your single S3 response serializer that specified what the expected response was. This would allow you to use a single response serializer for all the different types of responses. It would be very similar to the concept of validating a response status code.

Hopefully that helps.

from amazons3requestmanager.

AnthonyMDev avatar AnthonyMDev commented on July 24, 2024

@cnoon Thanks for your comments. I didn't even consider the initialization of the Request.

@sbhklr Looks like we have to go with custom serializers.

from amazons3requestmanager.

sebromero avatar sebromero commented on July 24, 2024

@cnoon @AnthonyMDev I don't quite see why this shouldn't work. Subclassing Request works for me. At least it compiles so far. And the instances of these subclasses don't have to be created by Alamofire but only by AmazonS3RequestManager. They would use the according serializer that still can be implemented as an extension of Request. The whole purpose is to provide the user of AmazonS3RequestManager with an API that ensures the usage of the correct serializer.

from amazons3requestmanager.

AnthonyMDev avatar AnthonyMDev commented on July 24, 2024

@sbhklr I'll check out whatever you come up with. Either way, I definitely think that we need the custom serializers. We know we can use those either way.

If you can get the Request subclasses to work, I'll check it out. I'm not sure how you are initializing the subclasses though without access to the initializers. I'm still concerned about the unintended consequences of subclassing Request. Especially after:

definitely don't subclass. -@cnoon

You might want to do the custom serializers in one PR and the subclasses in a second PR, that way we have the ability to merge the serializers themselves if the subclasses don't work out.

from amazons3requestmanager.

sebromero avatar sebromero commented on July 24, 2024

I think we can close this issue. The serializers work.

from amazons3requestmanager.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.