-
Notifications
You must be signed in to change notification settings - Fork 0
Bulk REST API
- Your Name: Ujjwal Thaakar
- Email Address: ujjwalthaakar@gmail.com
- GitHub Username: @ujjwalt
- Twitter Username: ujjwal_thaakar
- IRC Nickname: ujjwalt (irc.freenode.net)
- College/University: Institute of Technology, Nirma University
- Subject/Major: Information Technology
REST actions for resource collections
RoR hinges on the REST architecture and my project deals with implementing a CRUD API for REST resource collections as well as resource collection management using generators/scaffolding. In short this project deals with providing as extensive support for resource collections as enjoyed by individual resources.
I've been using rails since 6 months now and find it beautiful. I wish to contribute to rails but I haven't yet dug into the source code. The prerequisites of implementing this project match well with my skill set as detailed knowledge of rails code base is not required to begin with. I've been using ruby since more than a year now and am more than comfortable with it and I'm also familiar with HTTP as I'm a student of IT and networking is a major part of our curriculum.
There are 3 major aspects to look at :-
- Routing - how specific HTTP verbs should be matched to controller actions and how the rails routing DSL accommodates them.
- Parameter parsing - wether changes in (1) result in any changes in the parameter passing format
- Generators - how should the scaffold generators accommodate resource collections
Using the traditional example of a post resource, I suggest the following scheme along with a general structure for the code :-
Routing
These methods will be generated by default for resources :posts together with the APIs for individual resources.
-
GET /posts- fetches the entire resource collection - no change is required as it is already implemented and routes toindex -
POST /posts- creates multiple resources which are passed as an array. Routes tocreate_many -
PUT /posts- put is supposed to replace the entire collection. Rails 4 routes both put and patch toupdatefor individual resources but for collections we might route put requests to a separate method such asreplaceorreplace_allfor consistency's sake that atomically truncates the table posts and then creates rows with the parameters passed effectively simulating a DELETE and a POST but atomically at database level. Although being a duplication ofcreate_manyanddestroy_all, this database level lock automatically blocks simultaneous POSTs and DELETEs until completion. -
PATCH /posts- updates existing collection by routing toupdate_allwhich updates existing resources. Unidentified resources are ignored. -
DELETE /posts- routed todestroy_all
Parameter Parsing
-
GET /posts- An array ids. If an array ids is not specified then all resources are fetched else resources identified by ids are returned. -
POST /posts- An array posts consists of hashes representing each object to be created. -
PUT /posts- Same parameters asPOST. If the parameter posts is missing then this is same asDELETE. -
PATCH /posts- Same parameters asPOST/PUT. If the parameter posts is missing then nothing happens. -
DELETE /posts- An array ids. If ids is not specified then the entire collection is deleted else only the resources identified by ids are destroyed.
Generators The code below is only for structural purposes to give a rough idea of what happens there
-
GET /postsdef index ids = params[:ids] if ids.nil? # return all posts else # return posts represented by ids in appropriate format end end
-
POST /postsdef create_many posts = params[:posts] posts.each do |p| Post.new(p).save end end
-
PUT /postsdef replace_all # start a database level transaction # truncate the table posts # insert records based on the array of objects passed in params # end transaction # Can be represented as Post.replace(params[:posts]) end
-
PATCH /postsdef update_all posts = params[:posts] posts.each do |p| # patch existing post with p end # OR Posts.update(posts) # to make PATCH an atomic operation - not required end
-
DELETE /postsdef destroy_all ids = params[:ids] if ids.nil? # if ids is nil then truncate the table else # else delete the posts identified by ids[] end # OR Post.destroy(ids) end
The major milestones for this project will be :-
Start of coding: 17 June 2013
- Implement routing for collections to default methods of the given controller: 17 June - 1st July
- Write tests for collection routing and verify: 3rd July - 11th July
- Implement CRUD operations on
ActiveRecord::Basesuch asdestroy,updateandreplacethat work at the database level to improve the efficiency of bulk deletion and creation of records: 13th July - 3rd August - Write tests and benchmark extensively for the class operations implemented. Rectify bugs found: 5th August - 18th August
- Design default functions for action controller scaffolding that is easier for beginners to grasp: 19th August - 26th August
- Modify scaffold generators to incorporate the newly designed methods: 28th August - 31st August
- Write a test app that exploits the newly incorporated features: 2nd September - 8th September
- Evaluate how the new API can be further improved from the viewpoint of usability as well as efficiency in production deployments: 10th September - 16th September
- Write documentation for the work done: 17th September - 23rd September
October 1st: Results declared - party!
Note: I've given myself 1 day off between each milestone to relish on my achievement and eat cake
As rightly mentioned on the ideas page, RoR is being increasingly used as a backend for lightweight apps and out of the box support for bulk operations as enjoyed by individual resources is crucial to the framework. This is in accordance with Rail's approach of being a RESTful web framework.
I've been the maintainer for node_pcap for quite some months now and am actively working on letting out its first stable release in years by incorporating multisession support for packet captures.
I am just 20 years old and started programming quite late at 16. 2 years back I read Steve Levy's Hackers and it had a profound effect on me. I realised that computers and in particular software are damn complex and the more minds applied to it the better it is. As a proof just look at Windows :p
The point is that I believe in the idea of open source because it leads to better software that reaches a wider audience.
I live in India. My summer vacation begins on 17th May and college starts again on 15th July. So I can start off any time after 16th May. Given my academic constraints and other research work I should be able to complete the project somewhere in mid to late August.
I have my vacations till 14th July and until then I can easily spend up to 40 hours a week on this project or even more. Once my college starts this will go down to around 25-30 hours a week.
I'll be in Gandhinagar, Gujarat, India. I will shift my residence to Ahmedabad somewhere in mid June. Ahmedabad is only 25 Km away from Gandhinagar. They're almost twin cities.
What timezone will you be working in and what hours do you plan to work? (so we can best match mentors)
I will be working in Indian Standard Time (IST) which is UTC/GMT +5:30 hours. I will mostly work between 1900 to 0100 hours everyday as this suits my college and gym routine. Also I think this will better suit mentors in the West.
None except that my college starts on 15th July (a norm in India).
I'm applying for the first time.
Yes. I've applied for rewriting the mlab-ns service for Measurement labs in Go. This is because I'm very fluent with Go and its my favourite system programming language.
I've known about GSoC for more than a year now but never thought I was good enough for it. Finally I've gathered the courage. I applied because of the prestige of working for world renowned open source organisations under Google's banner. How better can it get? And I won't lie - the money is great too!
Web development was one of the first forays into computers and programming for me and I've never come across a beautiful framework like Rails. Everything just works as if it already knows what I'll need to do! The fun is doubled given that you get to program in Ruby which is easily the most beautiful programming language I've come across. Because of these reasons I wish to contribute to Rails and its my dream to become a core team member.
I want to participate because I love rails and want to improve it further by being an integral part of it in the long term.
Ruby on Rails should choose me because I'm passionate about ruby, programming and web development and being a quick leaner I'm sure I will be able to contribute positively to this community and the thousands of users who use it daily. I am the maintainer of node_pcap and am more than familiar with not only HTTP but various other protocols. I'm a very strong programmer, having stood in the top 10 on programming competitions at TechGig, a forum for indian students and IT professionals to come together for competitive programming. I have also held good ranks in Google Code Jam (1299 at peak). My primary focus this summer is GSoC and unlike my colleagues I have not applied for any internships as I plan to give my 100% to it. I am also very quick at understanding large code bases and am currently trying to implement Job control on the Minix kernel (there are no deadlines). Communication is not a problem as I'm very fluent in English (it was my primary medium of education) and I also speak Hindi and Gujarati. My approach is a continuos result based one as you would have guessed from my timeline and I will deliver concrete results with tests to back them up. Lastly I would like you to select me because for me this is not a summer affair. I really love rails and I plan to work on it wether selected or not.