# Update resource with PUT request
curl -X PUT https://api.example.com/resource/123 \
-H 'Content-Type: application/json' \
-d '{"key": "updated_value"}'
# Retrieve data with GET request
curl https://api.example.com/data
# Send data with POST request to a form endpoint
curl -X POST https://api.example.com/form-endpoint \
-d 'param1=value1¶m2=value2'
# Delete resource with DELETE request and Authorization header
curl -X DELETE https://api.example.com/resource/456 \
-H 'Authorization: Bearer your_access_token'
# Upload a file with POST request to an upload endpoint
curl -X POST https://api.example.com/upload-endpoint \
-H 'Content-Type: multipart/form-data' \
-F 'file=@/path/to/your/file.txt'
# Send JSON data with POST request to a secured endpoint with headers and authorization
curl -X POST https://api.example.com/post-endpoint \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer your_access_token' \
-d '{"username": "john_doe", "password": "secretpassword"}'
# Send JSON data with POST request to an endpoint with cookies
curl -X POST https://example.com/api/endpoint \
-H 'Content-Type: application/json' \
-H 'Cookie: sessionid=your_session_id' \
-d '{"key1": "value1", "key2": "value2"}'Various cURL Examples for API Interactions
Related Posts
More content you might like
Etherscan vs Infura: Choosing the Right API for Your Blockchain Application
- Decentralized Applications (dApps): If you’re building an application that needs to interact with Ethereum in real-time, such as sending transactions or calling smart contract functions.
- Wallets: If you are developing a wallet application that needs to sign and broadcast transactions.
- Smart Contract Deployment: Use Infura to deploy or interact with smart contracts on the Ethereum blockchain.
- Rate Limits: Etherscan’s free tier limits the number of API requests per second (usually around 5 per second). This is fine for querying data but can be limiting for large-scale applications that need to process a lot of data quickly.
- Pricing: Etherscan offers paid tiers that increase the API request limits.
بناء API متقدم باستخدام Laravel Passport للتوثيق
ثم أضف الطرق التالية إلى ملف AuthController.php:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class AuthController extends Controller
{
// تسجيل مستخدم جديد
public function register(Request $request)
{
$request->validate([
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
$user = User::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
$token = $user->createToken('LaravelPassportAPI')->accessToken;
return response()->json(['token' => $token], 201);
}
// تسجيل الدخول
public function login(Request $request)
{
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
$user = Auth::user();
$token = $user->createToken('LaravelPassportAPI')->accessToken;
return response()->json(['token' => $token], 200);
} else {
return response()->json(['error' => 'Unauthenticated'], 401);
}
}
// الحصول على بيانات المستخدم
public function user()
{
return response()->json(Auth::user(), 200);
}
}التعامل مع JSON في JavaScript: قراءة البيانات وكتابتها
في هذا الدليل، سنتعلم كيفية التعامل مع JSON في JavaScript، بما في ذلك قراءة البيانات وكتابتها.
JSON هو تنسيق يستخدم في تبادل البيانات يشبه الكائنات في JavaScript. يتكون JSON من أزواج مفتاح-قيمة (key-value pairs) تمامًا مثل الكائنات، وهو مدعوم في معظم لغات البرمجة.
AJAX with JavaScript: A Practical Guide
Fetch and update filtered data dynamically without reloading the entire page.
Automatically save user inputs (e.g., in a blog editor) without refreshing the page.
Discussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!