Showing posts with the label api

Load Testing Tool | Vegeta | API Vegeta testing tool

For Ubuntu Install in ubuntu           wget   amd64.tar.gz           tar xfz vegeta-12.5.1-linux-amd64.tar.gz           mv vegeta /usr/bin/vegeta #try with root user permission Shell Script to run  Create a file and paste following code #!/bin/bash touch post_targets.list #creating a file truncate -s 0 post_targets.list cat >./post_body.json <<EOF  {     "wifi": {       "ssid": "$SSID",       "pw":   "$PW"     }   } EOF echo 'PUT' > post_targets.list echo 'X-Site-Country:SG' >> post_targets.list echo 'X-App-Version: 1.0.0'  >> post_targets.list echo 'X-App-Platform: mobile_app'  >> post_targets.list echo 'Authorization:Bearer eyJraWQiOiJXWGZCdjZWQ2xLY09KOGJBVmhlZWRHLXI1ZVhNOUI4

Authentication via JWT in rails api's

gem 'jwt' add this gem to your gem file bundle install create a file in lib/json_web_token.rb and paste following code class JsonWebToken      SECRET_KEY = Rails.application.secrets.secret_key_base. to_s      def self.encode(payload, exp = 15.days.from_now)         payload[:exp] = exp.to_i        JWT.encode(payload, SECRET_KEY)      end     def self.decode(token)        decoded = JWT.decode(token, SECRET_KEY)[0] decoded     end end create another file config/initializers/jwt.rb and paste following code require 'json_web_token' Now inside controller/api/v1/ we will a parent class for our all end-points: api/v1/api_controller.rb class Api::V1::ApiController < ActionController::Base      protect_from_forgery with: :null_session      def autheticate_user         header = request.headers['Authorization']         header = header.split(' ').last if header         begin             @decoded = JsonWebToken.decode