]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/api/old_controller.rb
API JSON output
[rails.git] / app / controllers / api / old_controller.rb
index 862d14716f9b12e34c25e6629ada8d1b7e16b8e2..92c6d929575241e6ded45b30dd98301a77995e98 100644 (file)
@@ -16,6 +16,13 @@ module Api
     before_action :lookup_old_element, :except => [:history]
     before_action :lookup_old_element_versions, :only => [:history]
 
+    before_action :default_format_xml
+
+    # Set format to xml unless client requires a specific format
+    def default_format_xml
+      request.format = "xml" unless params[:format]
+    end
+
     def history
       # the .where() method used in the lookup_old_element_versions
       # call won't throw an error if no records are found, so we have
@@ -30,7 +37,10 @@ module Api
                end
 
       # Render the result
-      render :formats => [:xml]
+      respond_to do |format|
+        format.xml
+        format.json
+      end
     end
 
     def version
@@ -41,7 +51,10 @@ module Api
         response.last_modified = @old_element.timestamp
 
         # Render the result
-        render :formats => [:xml]
+        respond_to do |format|
+          format.xml
+          format.json
+        end
       end
     end