•  
      Internship #400104 Create an API without Authentication
    #400104
    Arpita Gumma (arpita.gumma)
    2025-01-30 10:24
    2025-01-30 10:24
    Details
    Create an API without Authentication

    API without authentication

      from flask import Flask jsonify
    
      app = flask( _name_ )
    
      @app.route('/hello', methods = ['GET'])
       def hello _ world():
    
            return jsonify({"message":"Hello.world!"})
      
       if_name_=="_main_";
    
          app.run(debug=True)
    

    1 Importing Flask and JSON Response Function

    from flask import Flask jsonify
    
       flask: is framework, help to build the web application and API
    
    
       jsonify: This is used to convert python data(like dictionaries) into JSON format which is the format APIs us to send data
    

    2 Creating the Flask app

     app = flask( _name_ )
     
     flask( _name_ ): it creates  a flask application object. the _name_ variable tells  to flask that this is main file where  app is defined
    

    3 Defining API endpoint

       @app.route('/hello', methods = ['GET'])
        def hello _ world():
    
         return jsonify({"message":"Hello.world!"})
         
         1. set up URL endpoint /hello.
    
           methods = ['GET'] this endpoint  only accept GET request(used for retrieving data)
    
    
         2.  hello _ world():
    
         this function will run when someone accesses the /hello endpoint.
    
         3.  return jsonify({"message":"Hello.world!"})
    
         It returns a JSON response with the message
    

    4 Running Flask App

     if_name_=="_main_";
    
          app.run(debug=True)
    
      1. this checks if the script is being run directly (not imported from another file)
    
    
      2. second line the flask development server
    
       debug=True, this one allows automatic reloading when we make code changes and shows errors in the browser.
    
    Empty
    Empty
    State of Progress
    2025-01-28
    Empty
    2025-01-29
    Arpita Gumma (arpita.gumma)
    Ajit kumar (ajit)
    2025-01-29
    Empty
    Attachments
    Empty
    References
    References list is empty