package api
import (
"encoding/json"
"errors"
"io"
module ApiErrorHandler
extend ActiveSupport::Concern
included do
rescue_from StandardError, with: :handle_standard_error
rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found
package types
import (
"bytes"
"encoding/json"
"time"
class AddOptimisticLockingToDocuments < ActiveRecord::Migration[7.1]
def change
add_column :documents, :lock_version, :integer, null: false, default: 0
add_index :documents, :updated_at
end
end
<?php
namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
module Idempotency
extend ActiveSupport::Concern
included do
before_action :check_idempotency_key, only: [:create, :update]
after_action :store_idempotent_response, only: [:create, :update]
module Api
module V1
class PostsController < ApplicationController
def create
post = current_user.posts.build(post_params)
from rest_framework import permissions
class IsOwnerOrReadOnly(permissions.BasePermission):
"""
Custom permission to only allow owners of an object to edit it.
INSTALLED_APPS += ['corsheaders']
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware', # Must be before CommonMiddleware
'django.middleware.common.CommonMiddleware',
# ... other middleware
package api
import (
"encoding/json"
"errors"
"io"
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :authenticate_user!
end
package api
import (
"net/http"
"strings"
)